Skip to content

Commit 5627695

Browse files
committed
clean up
1 parent 1e18674 commit 5627695

File tree

2 files changed

+15
-36
lines changed

2 files changed

+15
-36
lines changed

src/libraries/Common/src/System/IO/Hashing/XxHash3.cs

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -136,48 +136,27 @@ public static ulong HashToUInt64(ReadOnlySpan<byte> source, long seed = 0)
136136
uint length = (uint)source.Length;
137137
fixed (byte* sourcePtr = &MemoryMarshal.GetReference(source))
138138
{
139-
if (length <= 16)
139+
return length switch
140140
{
141-
return HashLength0To16(sourcePtr, length, (ulong)seed);
142-
}
143-
144-
if (length <= 128)
145-
{
146-
return HashLength17To128(sourcePtr, length, (ulong)seed);
147-
}
148-
149-
if (length <= MidSizeMaxBytes)
150-
{
151-
return HashLength129To240(sourcePtr, length, (ulong)seed);
152-
}
153-
154-
return HashLengthOver240(sourcePtr, length, (ulong)seed);
141+
<= 16 => HashLength0To16(sourcePtr, length, (ulong)seed),
142+
<= 128 => HashLength17To128(sourcePtr, length, (ulong)seed),
143+
<= MidSizeMaxBytes => HashLength129To240(sourcePtr, length, (ulong)seed),
144+
_ => HashLengthOver240(sourcePtr, length, (ulong)seed)
145+
};
155146
}
156147
}
157148

158149
#if SYSTEM_PRIVATE_CORELIB
159-
public static ulong NonRandomizedHashToUInt64(byte* sourcePtr, uint length)
150+
public static int NonRandomizedHashToInt32(byte* sourcePtr, uint length)
160151
{
161-
// We currently use this function only for large inputs from corelib's String.GetNonRandomizedHashCode,
162-
// so we don't need the fast path for small inputs.
163-
//
164-
// if (length <= 16)
165-
// {
166-
// return HashLength0To16(sourcePtr, length, (ulong)seed);
167-
// }
168-
Debug.Assert(length > 16);
169-
170-
if (length <= 128)
171-
{
172-
return HashLength17To128(sourcePtr, length, 0UL);
173-
}
174-
175-
if (length <= MidSizeMaxBytes)
152+
ulong hash = length switch
176153
{
177-
return HashLength129To240(sourcePtr, length, 0UL);
178-
}
179-
180-
return HashLengthOver240(sourcePtr, length, 0UL);
154+
<= 16 => HashLength0To16(sourcePtr, length, 0UL),
155+
<= 128 => HashLength17To128(sourcePtr, length, 0UL),
156+
<= MidSizeMaxBytes => HashLength129To240(sourcePtr, length, 0UL),
157+
_ => HashLengthOver240(sourcePtr, length, 0UL)
158+
};
159+
return unchecked((int)hash);
181160
}
182161
#endif
183162

src/libraries/System.Private.CoreLib/src/System/String.Comparison.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ internal static unsafe int GetNonRandomizedHashCode(ReadOnlySpan<char> span)
864864
if (length >= XxHash3Threshold)
865865
{
866866
uint byteLength = (uint)length * 2; // never overflows
867-
return unchecked((int)System.IO.Hashing.XxHash3.NonRandomizedHashToUInt64((byte*)src, byteLength));
867+
return System.IO.Hashing.XxHash3.NonRandomizedHashToInt32((byte*)src, byteLength);
868868
}
869869
#endif
870870

0 commit comments

Comments
 (0)