Skip to content

Commit c096203

Browse files
committed
[stdlib] add contiguous fast path in Array.replaceSubrange
1 parent bedda7e commit c096203

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
@@ -177,14 +177,19 @@ extension _ArrayBufferProtocol {
177177

178178
// place the values into the hole we created
179179
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)
180+
let done: Void? = newValues.withContiguousStorageIfAvailable {
181+
holeStart.initialize(from: $0.baseAddress!, count: newCount)
182+
}
183+
if done == nil {
184+
var place = holeStart
185+
var i = newValues.startIndex
186+
while place < holeEnd {
187+
place.initialize(to: newValues[i])
188+
place += 1
189+
newValues.formIndex(after: &i)
190+
}
191+
_expectEnd(of: newValues, is: i)
186192
}
187-
_expectEnd(of: newValues, is: i)
188193
}
189194
}
190195
}

0 commit comments

Comments
 (0)