From 2005a137172d33f551b4370600ee3fc582a71177 Mon Sep 17 00:00:00 2001 From: Bruce Bowyer-Smyth Date: Mon, 28 Sep 2015 06:47:43 +1000 Subject: [PATCH] String.StartsWith ordinal optimization --- src/mscorlib/src/System/String.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/mscorlib/src/System/String.cs b/src/mscorlib/src/System/String.cs index 8acafd6d5fc4..eb8fdd88a254 100644 --- a/src/mscorlib/src/System/String.cs +++ b/src/mscorlib/src/System/String.cs @@ -2556,10 +2556,12 @@ public Boolean StartsWith(String value, StringComparison comparisonType) { 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) {