Skip to content

Commit b57b5bb

Browse files
committed
move _forceCreateUniqueMutableBuffer{Impl} into _ArrayBufferProtocol extension
1 parent e0a31a9 commit b57b5bb

File tree

1 file changed

+62
-60
lines changed

1 file changed

+62
-60
lines changed

stdlib/public/core/Arrays.swift.gyb

+62-60
Original file line numberDiff line numberDiff line change
@@ -1214,8 +1214,8 @@ extension ${Self} : RangeReplaceableCollection, _ArrayProtocol {
12141214
@inline(never)
12151215
internal mutating func _copyToNewBuffer(oldCount: Int) {
12161216
let newCount = oldCount + 1
1217-
var newBuffer = _forceCreateUniqueMutableBuffer(
1218-
&_buffer, countForNewBuffer: oldCount, minNewCapacity: newCount)
1217+
var newBuffer = _buffer._forceCreateUniqueMutableBuffer(
1218+
countForNewBuffer: oldCount, minNewCapacity: newCount)
12191219
_buffer._arrayOutOfPlaceUpdate(
12201220
&newBuffer, oldCount, 0, _IgnorePointer())
12211221
}
@@ -1681,8 +1681,8 @@ internal func _arrayOutOfPlaceReplace<B, C>(
16811681

16821682
let growth = insertCount - bounds.count
16831683
let newCount = source.count + growth
1684-
var newBuffer = _forceCreateUniqueMutableBuffer(
1685-
&source, newCount: newCount, requiredCapacity: newCount)
1684+
var newBuffer = source._forceCreateUniqueMutableBuffer(
1685+
newCount: newCount, requiredCapacity: newCount)
16861686

16871687
source._arrayOutOfPlaceUpdate(
16881688
&newBuffer,
@@ -1823,58 +1823,60 @@ public func += <
18231823

18241824
//===--- generic helpers --------------------------------------------------===//
18251825

1826-
/// Create a unique mutable buffer that has enough capacity to hold 'newCount'
1827-
/// elements and at least 'requiredCapacity' elements. Set the count of the new
1828-
/// buffer to 'newCount'. The content of the buffer is uninitialized.
1829-
/// The formula used to compute the new buffers capacity is:
1830-
/// max(requiredCapacity, source.capacity) if newCount <= source.capacity
1831-
/// max(requiredCapacity, _growArrayCapacity(source.capacity)) otherwise
1832-
@inline(never)
1833-
internal func _forceCreateUniqueMutableBuffer<_Buffer : _ArrayBufferProtocol>(
1834-
_ source: inout _Buffer, newCount: Int, requiredCapacity: Int
1835-
) -> _ContiguousArrayBuffer<_Buffer.Element> {
1836-
return _forceCreateUniqueMutableBufferImpl(
1837-
&source, countForBuffer: newCount, minNewCapacity: newCount,
1838-
requiredCapacity: requiredCapacity)
1839-
}
1840-
1841-
/// Create a unique mutable buffer that has enough capacity to hold
1842-
/// 'minNewCapacity' elements and set the count of the new buffer to
1843-
/// 'countForNewBuffer'. The content of the buffer uninitialized.
1844-
/// The formula used to compute the new buffers capacity is:
1845-
/// max(minNewCapacity, source.capacity) if minNewCapacity <= source.capacity
1846-
/// max(minNewCapacity, _growArrayCapacity(source.capacity)) otherwise
1847-
@inline(never)
1848-
internal
1849-
func _forceCreateUniqueMutableBuffer<_Buffer : _ArrayBufferProtocol>(
1850-
_ source: inout _Buffer, countForNewBuffer: Int, minNewCapacity: Int
1851-
) -> _ContiguousArrayBuffer<_Buffer.Element> {
1852-
return _forceCreateUniqueMutableBufferImpl(
1853-
&source, countForBuffer: countForNewBuffer, minNewCapacity: minNewCapacity,
1854-
requiredCapacity: minNewCapacity)
1855-
}
1856-
1857-
/// Create a unique mutable buffer that has enough capacity to hold
1858-
/// 'minNewCapacity' elements and at least 'requiredCapacity' elements and set
1859-
/// the count of the new buffer to 'countForBuffer'. The content of the buffer
1860-
/// uninitialized.
1861-
/// The formula used to compute the new capacity is:
1862-
/// max(requiredCapacity, source.capacity) if minNewCapacity <= source.capacity
1863-
/// max(requiredCapacity, _growArrayCapacity(source.capacity)) otherwise
1864-
internal func _forceCreateUniqueMutableBufferImpl<_Buffer : _ArrayBufferProtocol>(
1865-
_ source: inout _Buffer, countForBuffer: Int, minNewCapacity: Int,
1866-
requiredCapacity: Int
1867-
) -> _ContiguousArrayBuffer<_Buffer.Element> {
1868-
_sanityCheck(countForBuffer >= 0)
1869-
_sanityCheck(requiredCapacity >= countForBuffer)
1870-
_sanityCheck(minNewCapacity >= countForBuffer)
1871-
1872-
let minimumCapacity = max(
1873-
requiredCapacity, minNewCapacity > source.capacity
1874-
? _growArrayCapacity(source.capacity) : source.capacity)
1875-
1876-
return _ContiguousArrayBuffer(
1877-
_uninitializedCount: countForBuffer, minimumCapacity: minimumCapacity)
1826+
extension _ArrayBufferProtocol {
1827+
/// Create a unique mutable buffer that has enough capacity to hold 'newCount'
1828+
/// elements and at least 'requiredCapacity' elements. Set the count of the new
1829+
/// buffer to 'newCount'. The content of the buffer is uninitialized.
1830+
/// The formula used to compute the new buffers capacity is:
1831+
/// max(requiredCapacity, source.capacity) if newCount <= source.capacity
1832+
/// max(requiredCapacity, _growArrayCapacity(source.capacity)) otherwise
1833+
@inline(never)
1834+
internal func _forceCreateUniqueMutableBuffer(
1835+
newCount: Int, requiredCapacity: Int
1836+
) -> _ContiguousArrayBuffer<Element> {
1837+
return _forceCreateUniqueMutableBufferImpl(
1838+
countForBuffer: newCount, minNewCapacity: newCount,
1839+
requiredCapacity: requiredCapacity)
1840+
}
1841+
1842+
/// Create a unique mutable buffer that has enough capacity to hold
1843+
/// 'minNewCapacity' elements and set the count of the new buffer to
1844+
/// 'countForNewBuffer'. The content of the buffer uninitialized.
1845+
/// The formula used to compute the new buffers capacity is:
1846+
/// max(minNewCapacity, source.capacity) if minNewCapacity <= source.capacity
1847+
/// max(minNewCapacity, _growArrayCapacity(source.capacity)) otherwise
1848+
@inline(never)
1849+
internal func _forceCreateUniqueMutableBuffer(
1850+
countForNewBuffer: Int, minNewCapacity: Int
1851+
) -> _ContiguousArrayBuffer<Element> {
1852+
return _forceCreateUniqueMutableBufferImpl(
1853+
countForBuffer: countForNewBuffer, minNewCapacity: minNewCapacity,
1854+
requiredCapacity: minNewCapacity)
1855+
}
1856+
1857+
/// Create a unique mutable buffer that has enough capacity to hold
1858+
/// 'minNewCapacity' elements and at least 'requiredCapacity' elements and set
1859+
/// the count of the new buffer to 'countForBuffer'. The content of the buffer
1860+
/// uninitialized.
1861+
/// The formula used to compute the new capacity is:
1862+
/// max(requiredCapacity, source.capacity) if minNewCapacity <= source.capacity
1863+
/// max(requiredCapacity, _growArrayCapacity(source.capacity)) otherwise
1864+
internal func _forceCreateUniqueMutableBufferImpl(
1865+
countForBuffer: Int, minNewCapacity: Int,
1866+
requiredCapacity: Int
1867+
) -> _ContiguousArrayBuffer<Element> {
1868+
_sanityCheck(countForBuffer >= 0)
1869+
_sanityCheck(requiredCapacity >= countForBuffer)
1870+
_sanityCheck(minNewCapacity >= countForBuffer)
1871+
1872+
// FIXME(Typechecker): Swift. prefix shouldn't be necessary (rdar://problem/28947708)
1873+
let minimumCapacity = Swift.max(requiredCapacity,
1874+
minNewCapacity > capacity
1875+
? _growArrayCapacity(capacity) : capacity)
1876+
1877+
return _ContiguousArrayBuffer(
1878+
_uninitializedCount: countForBuffer, minimumCapacity: minimumCapacity)
1879+
}
18781880
}
18791881

18801882
internal protocol _PointerFunction {
@@ -1993,8 +1995,8 @@ internal func _outlinedMakeUniqueBuffer<_Buffer>(
19931995
return
19941996
}
19951997

1996-
var newBuffer = _forceCreateUniqueMutableBuffer(
1997-
&buffer, newCount: bufferCount, requiredCapacity: bufferCount)
1998+
var newBuffer = buffer._forceCreateUniqueMutableBuffer(
1999+
newCount: bufferCount, requiredCapacity: bufferCount)
19982000
buffer._arrayOutOfPlaceUpdate(&newBuffer, bufferCount, 0, _IgnorePointer())
19992001
}
20002002

@@ -2014,8 +2016,8 @@ internal func _arrayReserve<_Buffer>(
20142016
return
20152017
}
20162018

2017-
var newBuffer = _forceCreateUniqueMutableBuffer(
2018-
&buffer, newCount: count, requiredCapacity: requiredCapacity)
2019+
var newBuffer = buffer._forceCreateUniqueMutableBuffer(
2020+
newCount: count, requiredCapacity: requiredCapacity)
20192021
buffer._arrayOutOfPlaceUpdate(&newBuffer, count, 0, _IgnorePointer())
20202022
}
20212023

0 commit comments

Comments
 (0)