Skip to content

Commit 6f77bf8

Browse files
committed
Revert string changes
1 parent ee54472 commit 6f77bf8

File tree

1 file changed

+5
-3
lines changed
  • src/libraries/System.Private.CoreLib/src/System

1 file changed

+5
-3
lines changed

src/libraries/System.Private.CoreLib/src/System/String.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,13 @@ public char[] ToCharArray(int startIndex, int length)
487487
[NonVersionable]
488488
public static bool IsNullOrEmpty([NotNullWhen(false)] string? value)
489489
{
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.
490494
// Ternary operator returning true/false prevents redundant asm generation:
491495
// 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;
493497
}
494498

495499
public static bool IsNullOrWhiteSpace([NotNullWhen(false)] string? value)
@@ -607,7 +611,6 @@ public StringRuneEnumerator EnumerateRunes()
607611
internal static unsafe int wcslen(char* ptr)
608612
{
609613
// 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.
611614
int length = SpanHelpers.IndexOf(ref *ptr, '\0', int.MaxValue);
612615
if (length < 0)
613616
{
@@ -621,7 +624,6 @@ internal static unsafe int wcslen(char* ptr)
621624
internal static unsafe int strlen(byte* ptr)
622625
{
623626
// 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.
625627
int length = SpanHelpers.IndexOf(ref *ptr, (byte)'\0', int.MaxValue);
626628
if (length < 0)
627629
{

0 commit comments

Comments
 (0)