[String.Index] Restore compound offsets.

Move the shifts to index creation time rather than index comparison
time. This seems to benefit micro benchmarks and cover up
inefficiencies in our generic index distance calculations.
This commit is contained in:
Michael Ilseman
2018-05-25 09:54:35 -07:00
parent 4ec98bb25c
commit 3ee17102ed
4 changed files with 41 additions and 34 deletions

View File

@@ -527,7 +527,7 @@ extension String.UnicodeScalarView {
if i == startIndex || i == endIndex {
return true
}
if i._transcodedOffset != 0 { return false }
if i.transcodedOffset != 0 { return false }
let i2 = _toCoreIndex(i)
if _fastPath(!UTF16.isTrailSurrogate(_guts[i2])) { return true }
return i2 == 0 || !UTF16.isLeadSurrogate(_guts[i2 &- 1])