Improve CompareOrdinalIgnoreCaseHelper by removing return from loop
authorStephen Toub <stoub@microsoft.com>
Thu, 23 Feb 2017 16:25:03 +0000 (11:25 -0500)
committerStephen Toub <stoub@microsoft.com>
Fri, 24 Feb 2017 03:10:24 +0000 (22:10 -0500)
Commit migrated from https://github.com/dotnet/coreclr/commit/d2eed087d4e74361ef7fe71bc7b10e1d8a3edc26

src/coreclr/src/mscorlib/src/System/String.Comparison.cs

index 54b52df..54dc086 100644 (file)
@@ -29,11 +29,12 @@ namespace System
             {
                 char* a = ap;
                 char* b = bp;
+                int charA = 0, charB = 0;
 
                 while (length != 0)
                 {
-                    int charA = *a;
-                    int charB = *b;
+                    charA = *a;
+                    charB = *b;
 
                     Debug.Assert((charA | charB) <= 0x7F, "strings have to be ASCII");
 
@@ -43,7 +44,7 @@ namespace System
 
                     //Return the (case-insensitive) difference between them.
                     if (charA != charB)
-                        return charA - charB;
+                        goto ReturnCharAMinusCharB; // TODO: Workaround for https://github.com/dotnet/coreclr/issues/9692
 
                     // Next char
                     a++; b++;
@@ -51,6 +52,9 @@ namespace System
                 }
 
                 return strA.Length - strB.Length;
+
+                ReturnCharAMinusCharB:
+                return charA - charB;
             }
         }