_BSubstring.UnicodeScalarView: Fix range-replacing mutations that don’t take indices

This commit is contained in:
Karoy Lorentey committed 2023-03-20 13:12:14 -07:00
1 parent b355480eb7
commit 64a8098bf9
1 file changed
+8 -5
@@ -257,14 +257,16 @@ extension _BSubstring.UnicodeScalarView: RangeReplaceableCollection {
}
internal mutating func append(_ newElement: UnicodeScalar) {
_mutateBasePreservingBounds(in: endIndex ..< endIndex) {
$0.append(newElement)
let i = endIndex
_mutateBasePreservingBounds(in: i ..< i) {
$0.insert(newElement, at: i)
}
}
internal mutating func append<S: Sequence<UnicodeScalar>>(contentsOf newElements: __owned S) {
_mutateBasePreservingBounds(in: endIndex ..< endIndex) {
$0.append(contentsOf: newElements)
let i = endIndex
_mutateBasePreservingBounds(in: i ..< i) {
$0.insert(contentsOf: newElements, at: i)
}
}
@@ -285,7 +287,8 @@ extension _BSubstring.UnicodeScalarView: RangeReplaceableCollection {
@discardableResult
internal mutating func remove(at i: Index) -> UnicodeScalar {
_mutateBasePreservingBounds(in: i ..< i) {
let j = self.index(after: i)
return _mutateBasePreservingBounds(in: i ..< j) {
$0.remove(at: i)
}
}