Better performance for string.CompareOrdinalHelper (dotnet/coreclr#6119)
authorJames Ko <jamesqko@gmail.com>
Wed, 20 Jul 2016 00:06:01 +0000 (20:06 -0400)
committerJan Kotas <jkotas@microsoft.com>
Wed, 20 Jul 2016 00:06:01 +0000 (17:06 -0700)
commitbc401703ff05008812632a6c82b799bfc5aea1d0
tree4f3f8e7162dc83ffac2398160d7db6eeb629ae15
parent407fe6b14dcad63cc047668366127a0199207733
Better performance for string.CompareOrdinalHelper (dotnet/coreclr#6119)

- For 64-bit, process a `long` at a time (and 3 longs per iteration of the loop), since it's the largest word size of the processor. This is what other functions, like `EqualsHelper` or `StartsWithOrdinalHelper` do.

- Make sure we perform aligned reads on 64-bit platforms

  - Strings (objects in general?) are allocated on an aligned word boundary (that is, divisible by 4/8). However, the offset to the chars (`OffsetToStringData`) is 12 on 64-bit platforms, meaning that if we read a long from the first char it will *not* be aligned. To fix this, first check for differences in the first/second chars and start the loop from there.

- Used `goto` within the loop code, so we don't have to keep making jumps in the common case.

I also removed a comment above the `String` class that seems to be outdated (seeing as there is no string constructor that accepts another string).

Commit migrated from https://github.com/dotnet/coreclr/commit/719c34f3fc205093cb137e73c608f3b58e1a144f
src/coreclr/src/mscorlib/src/System/String.cs