Skip to content

Commit

Permalink
Don't widen to Int128 in CastCache (#92984)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MichalStrehovsky committed Oct 5, 2023
1 parent 6e8259c commit ffa4ef7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ internal static CastResult TryGet(int[] table, nuint source, nuint target)
TableMask(ref tableData) = size - 1;

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

return table;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ internal bool TryGet(TKey key, out TValue? value)
ref Entry tableData = ref TableData(table);

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

return table;
Expand Down

0 comments on commit ffa4ef7

Please sign in to comment.