File tree Expand file tree Collapse file tree 1 file changed +5
-10
lines changed
libs/server/Objects/SortedSetGeo Expand file tree Collapse file tree 1 file changed +5
-10
lines changed Original file line number Diff line number Diff line change 33
44using System ;
55using System . Runtime . CompilerServices ;
6- using System . Runtime . InteropServices ;
76using System . Runtime . Intrinsics . X86 ;
87
98namespace Garnet . server
@@ -234,21 +233,17 @@ static uint Squash(ulong x)
234233 /// <returns>The standard textual representation of the given 52-bit GeoHash integer</returns>
235234 public static string GetGeoHashCode ( long hash )
236235 {
237- return string . Create ( CodeLength , state : hash , static ( chars , hashState ) =>
236+ return string . Create ( CodeLength , state : hash , static ( chars , hash ) =>
238237 {
239- // Reference to the start of the base-32 char table, which is stored as constant data.
240- ref var base32CharsBase = ref MemoryMarshal . GetReference ( "0123456789bcdefghjkmnpqrstuvwxyz"u8 ) ;
238+ var base32Chars = "0123456789bcdefghjkmnpqrstuvwxyz"u8 ;
241239
242240 for ( var i = 0 ; i < chars . Length ; i ++ )
243241 {
244- // Shift and mask the five most significant bits.
245- var tableIndex = ( nuint ) ( hashState >> ( BitsOfPrecision - 5 ) ) & 0x1F ;
246-
247- // By masking the five bits, the tableIndex is now guaranteed to be <= 31 so this is safe.
248- chars [ i ] = ( char ) Unsafe . Add ( ref base32CharsBase , tableIndex ) ;
242+ // Shift and mask the five most significant bits for index to the base-32 table.
243+ chars [ i ] = ( char ) base32Chars [ ( int ) ( hash >> ( BitsOfPrecision - 5 ) ) & 0x1F ] ;
249244
250245 // Shift the encoded bits out.
251- hashState <<= 5 ;
246+ hash <<= 5 ;
252247 }
253248 } ) ;
254249 }
You can’t perform that action at this time.
0 commit comments