Skip to content

Commit 8d2af45

Browse files
committed
[String] Normalization-boundary-before UTF-8 fast path.
All latiny (<0x300) scalars have normalization boundaries before them, so when asking if memory containing a scalar encoded in valid UTF-8 has a boundary before it, check if the leading byte definitely encodes a scalar less than 0x300.
1 parent 94942c5 commit 8d2af45

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

stdlib/public/core/NormalizedCodeUnitIterator.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,11 @@ extension UnsafeBufferPointer where Element == UInt8 {
131131
if index == 0 || index == count {
132132
return true
133133
}
134-
135134
assert(!_isContinuation(self[_unchecked: index]))
136135

136+
// Sub-300 latiny fast-path
137+
if self[_unchecked: index] < 0xCC { return true }
138+
137139
let cu = _decodeScalar(self, startingAt: index).0
138140
return cu._hasNormalizationBoundaryBefore
139141
}

0 commit comments

Comments
 (0)