@@ -389,7 +389,7 @@ out Unsafe.AsRef<Vector<ushort>>(output),
389
389
}
390
390
391
391
[ MethodImpl ( MethodImplOptions . AggressiveOptimization ) ]
392
- public unsafe static bool BytesOrdinalEqualsStringAndAscii ( string previousValue , ReadOnlySpan < byte > newValue )
392
+ public static bool BytesOrdinalEqualsStringAndAscii ( string previousValue , ReadOnlySpan < byte > newValue )
393
393
{
394
394
// previousValue is a previously materialized string which *must* have already passed validation.
395
395
Debug . Assert ( IsValidHeaderString ( previousValue ) ) ;
@@ -412,8 +412,8 @@ public unsafe static bool BytesOrdinalEqualsStringAndAscii(string previousValue,
412
412
// This isn't problematic as we know the maximum length is max string length (from test above)
413
413
// which is a signed value so half the size of the unsigned pointer value so we can safely add
414
414
// a Vector<byte>.Count to it without overflowing.
415
- var count = ( IntPtr ) newValue . Length ;
416
- var offset = ( IntPtr ) 0 ;
415
+ var count = ( nint ) newValue . Length ;
416
+ var offset = ( nint ) 0 ;
417
417
418
418
// Get references to the first byte in the span, and the first char in the string.
419
419
ref var bytes = ref MemoryMarshal . GetReference ( newValue ) ;
@@ -422,12 +422,12 @@ public unsafe static bool BytesOrdinalEqualsStringAndAscii(string previousValue,
422
422
do
423
423
{
424
424
// If Vector not-accelerated or remaining less than vector size
425
- if ( ! Vector . IsHardwareAccelerated || ( byte * ) ( offset + Vector < byte > . Count ) > ( byte * ) count )
425
+ if ( ! Vector . IsHardwareAccelerated || ( offset + Vector < byte > . Count ) > count )
426
426
{
427
427
if ( IntPtr . Size == 8 ) // Use Intrinsic switch for branch elimination
428
428
{
429
429
// 64-bit: Loop longs by default
430
- while ( ( byte * ) ( offset + sizeof ( long ) ) <= ( byte * ) count )
430
+ while ( ( offset + sizeof ( long ) ) <= count )
431
431
{
432
432
if ( ! WidenFourAsciiBytesToUtf16AndCompareToChars (
433
433
ref Unsafe . Add ( ref str , offset ) ,
@@ -441,7 +441,7 @@ ref Unsafe.Add(ref str, offset + 4),
441
441
442
442
offset += sizeof ( long ) ;
443
443
}
444
- if ( ( byte * ) ( offset + sizeof ( int ) ) <= ( byte * ) count )
444
+ if ( ( offset + sizeof ( int ) ) <= count )
445
445
{
446
446
if ( ! WidenFourAsciiBytesToUtf16AndCompareToChars (
447
447
ref Unsafe . Add ( ref str , offset ) ,
@@ -456,7 +456,7 @@ ref Unsafe.Add(ref str, offset),
456
456
else
457
457
{
458
458
// 32-bit: Loop ints by default
459
- while ( ( byte * ) ( offset + sizeof ( int ) ) <= ( byte * ) count )
459
+ while ( ( offset + sizeof ( int ) ) <= count )
460
460
{
461
461
if ( ! WidenFourAsciiBytesToUtf16AndCompareToChars (
462
462
ref Unsafe . Add ( ref str , offset ) ,
@@ -468,7 +468,7 @@ ref Unsafe.Add(ref str, offset),
468
468
offset += sizeof ( int ) ;
469
469
}
470
470
}
471
- if ( ( byte * ) ( offset + sizeof ( short ) ) <= ( byte * ) count )
471
+ if ( ( offset + sizeof ( short ) ) <= count )
472
472
{
473
473
if ( ! WidenTwoAsciiBytesToUtf16AndCompareToChars (
474
474
ref Unsafe . Add ( ref str , offset ) ,
@@ -479,7 +479,7 @@ ref Unsafe.Add(ref str, offset),
479
479
480
480
offset += sizeof ( short ) ;
481
481
}
482
- if ( ( byte * ) offset < ( byte * ) count )
482
+ if ( offset < count )
483
483
{
484
484
var ch = ( char ) Unsafe . Add ( ref bytes , offset ) ;
485
485
if ( ( ( ch & 0x80 ) != 0 ) || Unsafe . Add ( ref str , offset ) != ch )
@@ -527,11 +527,11 @@ ref Unsafe.Add(ref str, offset),
527
527
}
528
528
529
529
offset += Vector < byte > . Count ;
530
- } while ( ( byte * ) ( offset + Vector < byte > . Count ) <= ( byte * ) count ) ;
530
+ } while ( ( offset + Vector < byte > . Count ) <= count ) ;
531
531
532
532
// Vector path done, loop back to do non-Vector
533
533
// If is a exact multiple of vector size, bail now
534
- } while ( ( byte * ) offset < ( byte * ) count ) ;
534
+ } while ( offset < count ) ;
535
535
536
536
// If we get here (input is exactly a multiple of Vector length) then there are no inequalities via widening;
537
537
// so the input bytes are both ascii and a match to the string if it was converted via Encoding.ASCII.GetString(...)
@@ -651,7 +651,7 @@ private static bool AllBytesInUInt16AreAscii(ushort value)
651
651
return ( ( value & 0x8080u ) == 0 ) ;
652
652
}
653
653
654
- private unsafe static bool IsValidHeaderString ( string value )
654
+ private static bool IsValidHeaderString ( string value )
655
655
{
656
656
// Method for Debug.Assert to ensure BytesOrdinalEqualsStringAndAscii
657
657
// is not called with an unvalidated string comparitor.
0 commit comments