@@ -72,8 +72,8 @@ internal protocol _ArrayBufferProtocol
72
72
///
73
73
/// - Precondition: This buffer is backed by a uniquely-referenced
74
74
/// `_ContiguousArrayBuffer`.
75
- mutating func replace < C> (
76
- subRange : Range < Int > ,
75
+ mutating func replaceSubrange < C> (
76
+ _ subrange : Range < Int > ,
77
77
with newCount: Int ,
78
78
elementsOf newValues: C
79
79
) where C : Collection , C. Iterator. Element == Element
@@ -124,41 +124,42 @@ internal protocol _ArrayBufferProtocol
124
124
var identity : UnsafeRawPointer { get }
125
125
126
126
var startIndex : Int { get }
127
+ var endIndex : Int { get }
127
128
}
128
129
129
- extension _ArrayBufferProtocol where Index == Int {
130
+ extension _ArrayBufferProtocol {
130
131
131
132
internal var subscriptBaseAddress : UnsafeMutablePointer < Element > {
132
133
return firstElementAddress
133
134
}
134
135
135
- internal mutating func replace < C> (
136
- subRange : Range < Int > ,
136
+ internal mutating func replaceSubrange < C> (
137
+ _ subrange : Range < Int > ,
137
138
with newCount: Int ,
138
139
elementsOf newValues: C
139
140
) where C : Collection , C. Iterator. Element == Element {
140
141
_sanityCheck ( startIndex == 0 , " _SliceBuffer should override this function. " )
141
142
let oldCount = self . count
142
- let eraseCount = subRange . count
143
+ let eraseCount = subrange . count
143
144
144
145
let growth = newCount - eraseCount
145
146
self . count = oldCount + growth
146
147
147
148
let elements = self . subscriptBaseAddress
148
- let oldTailIndex = subRange . upperBound
149
+ let oldTailIndex = subrange . upperBound
149
150
let oldTailStart = elements + oldTailIndex
150
151
let newTailIndex = oldTailIndex + growth
151
152
let newTailStart = oldTailStart + growth
152
- let tailCount = oldCount - subRange . upperBound
153
+ let tailCount = oldCount - subrange . upperBound
153
154
154
155
if growth > 0 {
155
156
// Slide the tail part of the buffer forwards, in reverse order
156
157
// so as not to self-clobber.
157
158
newTailStart. moveInitialize ( from: oldTailStart, count: tailCount)
158
159
159
- // Assign over the original subRange
160
+ // Assign over the original subrange
160
161
var i = newValues. startIndex
161
- for j in CountableRange ( subRange ) {
162
+ for j in CountableRange ( subrange ) {
162
163
elements [ j] = newValues [ i]
163
164
newValues. formIndex ( after: & i)
164
165
}
@@ -170,12 +171,12 @@ extension _ArrayBufferProtocol where Index == Int {
170
171
_expectEnd ( of: newValues, is: i)
171
172
}
172
173
else { // We're not growing the buffer
173
- // Assign all the new elements into the start of the subRange
174
- var i = subRange . lowerBound
174
+ // Assign all the new elements into the start of the subrange
175
+ var i = subrange . lowerBound
175
176
var j = newValues. startIndex
176
177
for _ in 0 ..< newCount {
177
178
elements [ i] = newValues [ j]
178
- formIndex ( after : & i )
179
+ i += 1
179
180
newValues. formIndex ( after: & j)
180
181
}
181
182
_expectEnd ( of: newValues, is: j)
@@ -201,7 +202,7 @@ extension _ArrayBufferProtocol where Index == Int {
201
202
// Assign over the start of the replaced range with the tail
202
203
newTailStart. moveAssign ( from: oldTailStart, count: tailCount)
203
204
204
- // Destroy elements remaining after the tail in subRange
205
+ // Destroy elements remaining after the tail in subrange
205
206
( newTailStart + tailCount) . deinitialize (
206
207
count: shrinkage - tailCount)
207
208
}
0 commit comments