Skip to content

Commit dbaada4

Browse files
committed
Stay in vectors longer before doing a horizontal sum
1 parent f2ce515 commit dbaada4

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

stdlib/public/core/StringUTF16View.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -533,14 +533,18 @@ extension String.UTF16View {
533533
//Find the number of continuations (0b10xxxxxx)
534534
let sValue = Builtin.loadRaw(readPtr._rawValue) as S
535535
let continuations = S.zero.replacing(with: S.one, where: sValue .< -65 + 1)
536-
let continuationCount = Int(continuations.wrappedSum())
537536

538537
//Find the number of 4 byte code points (0b11110xxx)
539538
let uValue = Builtin.loadRaw(readPtr._rawValue) as U
540-
let fourBytes = U.zero.replacing(with: U.one, where: uValue .>= 0b11110000)
541-
let fourByteCount = Int(fourBytes.wrappedSum())
542-
543-
utf16Count &+= (U.scalarCount - continuationCount) + fourByteCount
539+
let fourBytes = S.zero.replacing(
540+
with: S.one,
541+
where: unsafeBitCast(
542+
uValue .>= 0b11110000,
543+
to: SIMDMask<S.MaskStorage>.self
544+
)
545+
)
546+
547+
utf16Count &+= U.scalarCount + Int((fourBytes &- continuations).wrappedSum())
544548

545549
readPtr += MemoryLayout<U>.stride
546550
}

0 commit comments

Comments
 (0)