Skip to content

Commit f84dd82

Browse files
committed
[stdlib] add contiguous fast path in Array.replaceSubrange
1 parent 55d8e26 commit f84dd82

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

stdlib/public/core/ArrayBufferProtocol.swift

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,19 @@ extension _ArrayBufferProtocol {
173173

174174
// place the values into the hole we created
175175
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)
176+
let done: Void? = newValues.withContiguousStorageIfAvailable {
177+
holeStart.initialize(from: $0.baseAddress!, count: newCount)
178+
}
179+
if done == nil {
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)
182188
}
183-
_expectEnd(of: newValues, is: i)
184189
}
185190
}
186191
}

0 commit comments

Comments
 (0)