[String] Speed up constant factors on comparison.

Include some tuning and tweaking to reduce the constant factors
involved in string comparison. This yields considerable improvement on
our micro-benchmarks, and allows us to make less inlinable code and
have a smaller ABI surface area.

Adds more extensive testing of corner cases in our existing
fast-paths.
This commit is contained in:
Michael Ilseman
2018-12-03 13:24:02 -08:00
parent 1706d4c02d
commit c0c530aef8
6 changed files with 261 additions and 216 deletions

View File

@@ -153,18 +153,11 @@ extension _StringGuts {
@inlinable @inline(__always)
internal func withFastUTF8<R>(
range: Range<Int>?,
range: Range<Int>,
_ f: (UnsafeBufferPointer<UInt8>) throws -> R
) rethrows -> R {
return try self.withFastUTF8 { wholeUTF8 in
let slicedUTF8: UnsafeBufferPointer<UInt8>
if let r = range {
slicedUTF8 = UnsafeBufferPointer(rebasing: wholeUTF8[r])
} else {
slicedUTF8 = wholeUTF8
}
return try f(slicedUTF8)
return try f(UnsafeBufferPointer(rebasing: wholeUTF8[range]))
}
}