Skip to content

Commit 740d037

Browse files
committed
Try using withContiguousStorageIfAvailable in RangeReplaceableCollection.append(contentsOf:) before falling back to a slow element-by-element loop. Fixes rdar://109059874
1 parent 595aefd commit 740d037

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

stdlib/public/core/RangeReplaceableCollection.swift

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -453,11 +453,18 @@ extension RangeReplaceableCollection {
453453
@inlinable
454454
public mutating func append<S: Sequence>(contentsOf newElements: __owned S)
455455
where S.Element == Element {
456-
457-
let approximateCapacity = self.count + newElements.underestimatedCount
458-
self.reserveCapacity(approximateCapacity)
459-
for element in newElements {
460-
append(element)
456+
457+
let done:Void? = newElements.withContiguousStorageIfAvailable {
458+
_onFastPath()
459+
replaceSubrange(endIndex..<endIndex, $0)
460+
}
461+
462+
if done == nil {
463+
let approximateCapacity = self.count + newElements.underestimatedCount
464+
self.reserveCapacity(approximateCapacity)
465+
for element in newElements {
466+
append(element)
467+
}
461468
}
462469
}
463470

0 commit comments

Comments
 (0)