Skip to content

Commit 2423b8b

Browse files
committed
[stdlib] StringProtocol._toUTF16Indices: Speed up conversion of short ranges
Instead of calling `_toUTF16Index` twice, call it once and then use `index(_:offsetBy:)` to potentially avoid another breadcrumbs lookup.
1 parent f3a9305 commit 2423b8b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

stdlib/public/core/StringBridge.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ extension StringProtocol {
807807
public // SPI(Foundation)
808808
func _toUTF16Indices(_ range: Range<Int>) -> Range<Index> {
809809
let lowerbound = _toUTF16Index(range.lowerBound)
810-
let upperbound = _toUTF16Index(range.lowerBound + range.count)
810+
let upperbound = self.utf16.index(lowerbound, offsetBy: range.count)
811811
return Range(uncheckedBounds: (lower: lowerbound, upper: upperbound))
812812
}
813813
}

0 commit comments

Comments
 (0)