From 68c2cef28a91dceaeb638b3934549f8475c46004 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Thu, 23 Feb 2017 11:25:03 -0500 Subject: [PATCH] Improve CompareOrdinalIgnoreCaseHelper by removing return from loop Commit migrated from https://github.com/dotnet/coreclr/commit/d2eed087d4e74361ef7fe71bc7b10e1d8a3edc26 --- src/coreclr/src/mscorlib/src/System/String.Comparison.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/coreclr/src/mscorlib/src/System/String.Comparison.cs b/src/coreclr/src/mscorlib/src/System/String.Comparison.cs index 54b52df..54dc086 100644 --- a/src/coreclr/src/mscorlib/src/System/String.Comparison.cs +++ b/src/coreclr/src/mscorlib/src/System/String.Comparison.cs @@ -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; } } -- 2.7.4