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