Skip to content

Commit 3cc9b7f

Browse files
committed
move _arrayOutOfPlaceReplace into _ArrayBufferProtocol extension
1 parent 3752e6d commit 3cc9b7f

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

Diff for: stdlib/public/core/Arrays.swift.gyb

+21-24
Original file line numberDiff line numberDiff line change
@@ -1666,29 +1666,26 @@ internal struct _InitializeMemoryFromCollection<
16661666
var newValues: C
16671667
}
16681668

1669-
// FIXME(ABI)#14 : add argument labels.
1670-
@inline(never)
1671-
internal func _arrayOutOfPlaceReplace<B, C>(
1672-
_ source: inout B,
1673-
_ bounds: Range<Int>,
1674-
_ newValues: C,
1675-
_ insertCount: Int
1676-
) where
1677-
B : _ArrayBufferProtocol,
1678-
C : Collection,
1679-
C.Iterator.Element == B.Element,
1680-
B.Index == Int {
1681-
1682-
let growth = insertCount - bounds.count
1683-
let newCount = source.count + growth
1684-
var newBuffer = source._forceCreateUniqueMutableBuffer(
1685-
newCount: newCount, requiredCapacity: newCount)
1686-
1687-
source._arrayOutOfPlaceUpdate(
1688-
&newBuffer,
1689-
bounds.lowerBound - source.startIndex, insertCount,
1690-
_InitializeMemoryFromCollection(newValues)
1691-
)
1669+
extension _ArrayBufferProtocol where Index == Int {
1670+
// FIXME(ABI)#14 : add argument labels.
1671+
@inline(never)
1672+
internal mutating func _arrayOutOfPlaceReplace<C : Collection>(
1673+
_ bounds: Range<Int>,
1674+
_ newValues: C,
1675+
_ insertCount: Int
1676+
) where C.Iterator.Element == Element {
1677+
1678+
let growth = insertCount - bounds.count
1679+
let newCount = count + growth
1680+
var newBuffer = _forceCreateUniqueMutableBuffer(
1681+
newCount: newCount, requiredCapacity: newCount)
1682+
1683+
_arrayOutOfPlaceUpdate(
1684+
&newBuffer,
1685+
bounds.lowerBound - startIndex, insertCount,
1686+
_InitializeMemoryFromCollection(newValues)
1687+
)
1688+
}
16921689
}
16931690

16941691
/// A _debugPrecondition check that `i` has exactly reached the end of
@@ -1767,7 +1764,7 @@ extension ${Self} {
17671764
self._buffer.replace(
17681765
subRange: subrange, with: insertCount, elementsOf: newElements)
17691766
} else {
1770-
_arrayOutOfPlaceReplace(&self._buffer, subrange, newElements, insertCount)
1767+
_buffer._arrayOutOfPlaceReplace(subrange, newElements, insertCount)
17711768
}
17721769
}
17731770
}

0 commit comments

Comments
 (0)