23 lines
610 B
C#
23 lines
610 B
C#
using System.IO.Hashing;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace ContentProxy;
|
|
|
|
public sealed class CacheKeyComparer : StringComparer
|
|
{
|
|
internal static readonly CacheKeyComparer Instance = new();
|
|
|
|
private CacheKeyComparer()
|
|
{ }
|
|
|
|
public override int Compare(string? x, string? y) => string.CompareOrdinal(x, y);
|
|
|
|
public override bool Equals(string? x, string? y) => string.Equals(x, y);
|
|
|
|
public override int GetHashCode(string obj)
|
|
{
|
|
ArgumentException.ThrowIfNullOrWhiteSpace(obj);
|
|
|
|
return unchecked((int)XxHash32.HashToUInt32(MemoryMarshal.AsBytes<char>(obj)));
|
|
}
|
|
}
|