@@ -487,9 +487,13 @@ public char[] ToCharArray(int startIndex, int length)
487
487
[ NonVersionable ]
488
488
public static bool IsNullOrEmpty ( [ NotNullWhen ( false ) ] string ? value )
489
489
{
490
+ // Using 0u >= (uint)value.Length rather than
491
+ // value.Length == 0 as it will elide the bounds check to
492
+ // the first char: value[0] if that is performed following the test
493
+ // for the same test cost.
490
494
// Ternary operator returning true/false prevents redundant asm generation:
491
495
// https://github.com/dotnet/runtime/issues/4207
492
- return ( value == null || 0 == value . Length ) ? true : false ;
496
+ return ( value == null || 0u >= ( uint ) value . Length ) ? true : false ;
493
497
}
494
498
495
499
public static bool IsNullOrWhiteSpace ( [ NotNullWhen ( false ) ] string ? value )
@@ -607,7 +611,6 @@ public StringRuneEnumerator EnumerateRunes()
607
611
internal static unsafe int wcslen ( char * ptr )
608
612
{
609
613
// IndexOf processes memory in aligned chunks, and thus it won't crash even if it accesses memory beyond the null terminator.
610
- // This IndexOf behavior is an implementation detail of the runtime and callers outside System.Private.CoreLib must not depend on it.
611
614
int length = SpanHelpers . IndexOf ( ref * ptr , '\0 ' , int . MaxValue ) ;
612
615
if ( length < 0 )
613
616
{
@@ -621,7 +624,6 @@ internal static unsafe int wcslen(char* ptr)
621
624
internal static unsafe int strlen ( byte * ptr )
622
625
{
623
626
// IndexOf processes memory in aligned chunks, and thus it won't crash even if it accesses memory beyond the null terminator.
624
- // This IndexOf behavior is an implementation detail of the runtime and callers outside System.Private.CoreLib must not depend on it.
625
627
int length = SpanHelpers . IndexOf ( ref * ptr , ( byte ) '\0 ' , int . MaxValue ) ;
626
628
if ( length < 0 )
627
629
{
0 commit comments