Skip to content

Commit ffa4ef7

Browse files
Don't widen to Int128 in CastCache (#92984)
Leftover change from hackathon. Existing code is widening to Int128 and then counting zeros. It still worked because we only use it for bit shifting and bit shifts do wrap around if they're > 64. But this was bringing Int128 into `Runtime.Base` in my hackathon project.
1 parent 6e8259c commit ffa4ef7

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastCache.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ internal static CastResult TryGet(int[] table, nuint source, nuint target)
250250
TableMask(ref tableData) = size - 1;
251251

252252
// Fibonacci hash reduces the value into desired range by shifting right by the number of leading zeroes in 'size-1'
253-
byte shift = (byte)BitOperations.LeadingZeroCount(size - 1);
253+
byte shift = (byte)BitOperations.LeadingZeroCount((nuint)(size - 1));
254254
HashShift(ref tableData) = shift;
255255

256256
return table;

src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/GenericCache.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ internal bool TryGet(TKey key, out TValue? value)
230230
ref Entry tableData = ref TableData(table);
231231

232232
// Fibonacci hash reduces the value into desired range by shifting right by the number of leading zeroes in 'size-1'
233-
byte shift = (byte)BitOperations.LeadingZeroCount(size - 1);
233+
byte shift = (byte)BitOperations.LeadingZeroCount((nuint)(size - 1));
234234
HashShift(table) = shift;
235235

236236
return table;

0 commit comments

Comments
 (0)