@@ -136,48 +136,27 @@ public static ulong HashToUInt64(ReadOnlySpan<byte> source, long seed = 0)
136
136
uint length = ( uint ) source . Length ;
137
137
fixed ( byte * sourcePtr = & MemoryMarshal . GetReference ( source ) )
138
138
{
139
- if ( length <= 16 )
139
+ return length switch
140
140
{
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
+ } ;
155
146
}
156
147
}
157
148
158
149
#if SYSTEM_PRIVATE_CORELIB
159
- public static ulong NonRandomizedHashToUInt64 ( byte * sourcePtr , uint length )
150
+ public static int NonRandomizedHashToInt32 ( byte * sourcePtr , uint length )
160
151
{
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
176
153
{
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 ) ;
181
160
}
182
161
#endif
183
162
0 commit comments