File tree Expand file tree Collapse file tree 1 file changed +7
-17
lines changed
src/libraries/System.Private.CoreLib/src/System Expand file tree Collapse file tree 1 file changed +7
-17
lines changed Original file line number Diff line number Diff line change @@ -727,27 +727,17 @@ private static bool TryParseExactX(ReadOnlySpan<char> guidString, ref GuidResult
727727 }
728728
729729 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
730- private static byte DecodeByte ( nuint ch1 , nuint ch2 , ref int invalidIfNegative )
730+ private static byte DecodeByte ( char ch1 , char ch2 , ref int invalidIfNegative )
731731 {
732- // TODO https://github.com/dotnet/runtime/issues/13464:
733- // Replace the Unsafe.Add with HexConverter.FromChar once the bounds checks are eliminated.
734-
735732 ReadOnlySpan < byte > lookup = HexConverter . CharToHexLookup ;
733+ Debug . Assert ( lookup . Length == 256 ) ;
736734
737- int h1 = - 1 ;
738- if ( ch1 < ( nuint ) lookup . Length )
739- {
740- h1 = ( sbyte ) Unsafe . Add ( ref MemoryMarshal . GetReference ( lookup ) , ( nint ) ch1 ) ;
741- }
742- h1 <<= 4 ;
743-
744- int h2 = - 1 ;
745- if ( ch2 < ( nuint ) lookup . Length )
746- {
747- h2 = ( sbyte ) Unsafe . Add ( ref MemoryMarshal . GetReference ( lookup ) , ( nint ) ch2 ) ;
748- }
735+ int upper = ( sbyte ) lookup [ ( byte ) ch1 ] ;
736+ int lower = ( sbyte ) lookup [ ( byte ) ch2 ] ;
737+ int result = ( upper << 4 ) | lower ;
749738
750- int result = h1 | h2 ;
739+ // Result will be negative if ch1 or/and ch2 are greater than 0xFF
740+ result = ( ch1 | ch2 ) >> 8 == 0 ? result : - 1 ;
751741 invalidIfNegative |= result ;
752742 return ( byte ) result ;
753743 }
You can’t perform that action at this time.
0 commit comments