@@ -474,19 +474,23 @@ public static ulong GetKey(ReadOnlySpan<byte> name)
474
474
}
475
475
476
476
// Verify key contains the embedded bytes as expected.
477
- const int BitsInByte = 8 ;
478
- Debug . Assert (
479
- // Verify embedded property name.
480
- ( name . Length < 1 || name [ 0 ] == ( ( key & ( ( ulong ) 0xFF << BitsInByte * 0 ) ) >> BitsInByte * 0 ) ) &&
481
- ( name . Length < 2 || name [ 1 ] == ( ( key & ( ( ulong ) 0xFF << BitsInByte * 1 ) ) >> BitsInByte * 1 ) ) &&
482
- ( name . Length < 3 || name [ 2 ] == ( ( key & ( ( ulong ) 0xFF << BitsInByte * 2 ) ) >> BitsInByte * 2 ) ) &&
483
- ( name . Length < 4 || name [ 3 ] == ( ( key & ( ( ulong ) 0xFF << BitsInByte * 3 ) ) >> BitsInByte * 3 ) ) &&
484
- ( name . Length < 5 || name [ 4 ] == ( ( key & ( ( ulong ) 0xFF << BitsInByte * 4 ) ) >> BitsInByte * 4 ) ) &&
485
- ( name . Length < 6 || name [ 5 ] == ( ( key & ( ( ulong ) 0xFF << BitsInByte * 5 ) ) >> BitsInByte * 5 ) ) &&
486
- ( name . Length < 7 || name [ 6 ] == ( ( key & ( ( ulong ) 0xFF << BitsInByte * 6 ) ) >> BitsInByte * 6 ) ) &&
487
- // Verify embedded length.
488
- ( name . Length >= 0xFF || ( key & ( ( ulong ) 0xFF << BitsInByte * 7 ) ) >> BitsInByte * 7 == ( ulong ) name . Length ) &&
489
- ( name . Length < 0xFF || ( key & ( ( ulong ) 0xFF << BitsInByte * 7 ) ) >> BitsInByte * 7 == 0xFF ) ) ;
477
+ // Note: the expected properties do not hold true on big-endian platforms
478
+ if ( BitConverter . IsLittleEndian )
479
+ {
480
+ const int BitsInByte = 8 ;
481
+ Debug . Assert (
482
+ // Verify embedded property name.
483
+ ( name . Length < 1 || name [ 0 ] == ( ( key & ( ( ulong ) 0xFF << BitsInByte * 0 ) ) >> BitsInByte * 0 ) ) &&
484
+ ( name . Length < 2 || name [ 1 ] == ( ( key & ( ( ulong ) 0xFF << BitsInByte * 1 ) ) >> BitsInByte * 1 ) ) &&
485
+ ( name . Length < 3 || name [ 2 ] == ( ( key & ( ( ulong ) 0xFF << BitsInByte * 2 ) ) >> BitsInByte * 2 ) ) &&
486
+ ( name . Length < 4 || name [ 3 ] == ( ( key & ( ( ulong ) 0xFF << BitsInByte * 3 ) ) >> BitsInByte * 3 ) ) &&
487
+ ( name . Length < 5 || name [ 4 ] == ( ( key & ( ( ulong ) 0xFF << BitsInByte * 4 ) ) >> BitsInByte * 4 ) ) &&
488
+ ( name . Length < 6 || name [ 5 ] == ( ( key & ( ( ulong ) 0xFF << BitsInByte * 5 ) ) >> BitsInByte * 5 ) ) &&
489
+ ( name . Length < 7 || name [ 6 ] == ( ( key & ( ( ulong ) 0xFF << BitsInByte * 6 ) ) >> BitsInByte * 6 ) ) &&
490
+ // Verify embedded length.
491
+ ( name . Length >= 0xFF || ( key & ( ( ulong ) 0xFF << BitsInByte * 7 ) ) >> BitsInByte * 7 == ( ulong ) name . Length ) &&
492
+ ( name . Length < 0xFF || ( key & ( ( ulong ) 0xFF << BitsInByte * 7 ) ) >> BitsInByte * 7 == 0xFF ) ) ;
493
+ }
490
494
491
495
return key ;
492
496
}
0 commit comments