@@ -163,21 +163,28 @@ extension _ArrayBufferProtocol {
163
163
// erase all the elements we're replacing to create a hole
164
164
let holeStart = elements + subrange. lowerBound
165
165
let holeEnd = holeStart + newCount
166
- holeStart. deinitialize ( count: eraseCount)
166
+
167
+ if eraseCount > 0 {
168
+ holeStart. deinitialize ( count: eraseCount)
169
+ }
167
170
168
171
// resize the hole to make it the correct size
169
- let tailStart = elements + subrange. upperBound
170
- let tailCount = oldCount - subrange. upperBound
171
- holeEnd. moveInitialize ( from: tailStart, count: tailCount)
172
+ if growth != 0 {
173
+ let tailStart = elements + subrange. upperBound
174
+ let tailCount = oldCount - subrange. upperBound
175
+ holeEnd. moveInitialize ( from: tailStart, count: tailCount)
176
+ }
172
177
173
178
// place the values into the hole we created
174
- var place = holeStart
175
- var i = newValues. startIndex
176
- while place < holeEnd {
177
- place. initialize ( to: newValues [ i] )
178
- place += 1
179
- newValues. formIndex ( after: & i)
179
+ if newCount > 0 {
180
+ var place = holeStart
181
+ var i = newValues. startIndex
182
+ while place < holeEnd {
183
+ place. initialize ( to: newValues [ i] )
184
+ place += 1
185
+ newValues. formIndex ( after: & i)
186
+ }
187
+ _expectEnd ( of: newValues, is: i)
180
188
}
181
- _expectEnd ( of: newValues, is: i)
182
189
}
183
190
}
0 commit comments