String.StartsWith ordinal optimization
authorBruce Bowyer-Smyth <bbowyersmyth@live.com.au>
Sun, 27 Sep 2015 20:47:43 +0000 (06:47 +1000)
committerBruce Bowyer-Smyth <bbowyersmyth@live.com.au>
Sun, 27 Sep 2015 20:47:43 +0000 (06:47 +1000)
src/mscorlib/src/System/String.cs

index 8acafd6..eb8fdd8 100644 (file)
@@ -2556,10 +2556,12 @@ namespace System {
                     return CultureInfo.InvariantCulture.CompareInfo.IsPrefix(this, value, CompareOptions.IgnoreCase);                    
 
                 case StringComparison.Ordinal:
-                    if( this.Length < value.Length) {
+                    if( this.Length < value.Length || m_firstChar != value.m_firstChar) {
                         return false;
                     }
-                    return (nativeCompareOrdinalEx(this, 0, value, 0, value.Length) == 0);
+                    return (value.Length == 1) ?
+                            true :                 // First char is the same and thats all there is to compare
+                            (nativeCompareOrdinalEx(this, 0, value, 0, value.Length) == 0);
 
                 case StringComparison.OrdinalIgnoreCase:
                     if( this.Length < value.Length) {