Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

String.StartsWith ordinal optimization #1632

Merged
merged 1 commit into from
Sep 29, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/mscorlib/src/System/String.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down