Fast path IndexOf and variants for ASCII
authorMatt Ellis <matell@microsoft.com>
Wed, 13 Jan 2016 01:01:02 +0000 (17:01 -0800)
committerMatt Ellis <matell@microsoft.com>
Wed, 13 Jan 2016 21:37:19 +0000 (13:37 -0800)
commit8c82dd5428bdab80ce2f1a0803747c2406b9f178
treeb8c0887576701da825ba29e3e42f08689981f1f5
parentb8a0a62e41fa236ff1463523c3a287321a65bcff
Fast path IndexOf and variants for ASCII

In ICU doing any sort of index of operation (which includes Prefix and
Suffix checking) is relatively expensive. ICU ends up doing a fair
amount of work and allocations in order to construct a searcher object
which could be reused, but our APIs are not amenable towards working in
this manner.

However, for some cultures we can often fast path ASCII searches when we
know that ASCII and Ordinal comparisions are the same, as is the case
for both Invariant and en-US.

This change has CompareInfo hold some additional state about a locale to
decide if we can do this optimiztion and then wires it up to IndexOf,
LastIndexOf, IsPrefix and IsSuffix.

In the future, we can try to extend the set of allowable cultures that
we preform this optimization on by coming up with better checks on when
it is safe to preform this transformation.

Today, this optimization does not apply when IgnoreSymbols is set,
because we would need to blank some ASCII symbol characters. If this
ends up being a common operation, we could consider having ordinal
implementations that also ignore symbols.

This represents the best that we can do for dotnet/corefx#3672. It gets
us back to where we were before for many common real world cases.

Fixes dotnet/corefx#3672.
src/mscorlib/corefx/System/Globalization/CompareInfo.Unix.cs