Skip to content

Commit 6e841e0

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

File tree

1 file changed

+24
-30
lines changed

1 file changed

+24
-30
lines changed

stdlib/public/core/Arrays.swift.gyb

+24-30
Original file line numberDiff line numberDiff line change
@@ -1982,43 +1982,37 @@ internal struct _IgnorePointer<T> : _PointerFunction {
19821982
}
19831983
}
19841984

1985-
@_versioned
1986-
@inline(never)
1987-
internal func _outlinedMakeUniqueBuffer<_Buffer>(
1988-
_ buffer: inout _Buffer, bufferCount: Int
1989-
) where
1990-
_Buffer : _ArrayBufferProtocol,
1991-
_Buffer.Index == Int {
1985+
extension _ArrayBufferProtocol where Index == Int {
1986+
@_versioned
1987+
@inline(never)
1988+
internal func _outlinedMakeUniqueBuffer(bufferCount: Int) {
19921989

1993-
if _fastPath(
1994-
buffer.requestUniqueMutableBackingBuffer(minimumCapacity: bufferCount) != nil) {
1995-
return
1990+
if _fastPath(
1991+
requestUniqueMutableBackingBuffer(minimumCapacity: bufferCount) != nil) {
1992+
return
1993+
}
1994+
1995+
var newBuffer = _forceCreateUniqueMutableBuffer(
1996+
newCount: bufferCount, requiredCapacity: bufferCount)
1997+
_arrayOutOfPlaceUpdate(&newBuffer, bufferCount, 0, _IgnorePointer())
19961998
}
19971999

1998-
var newBuffer = buffer._forceCreateUniqueMutableBuffer(
1999-
newCount: bufferCount, requiredCapacity: bufferCount)
2000-
buffer._arrayOutOfPlaceUpdate(&newBuffer, bufferCount, 0, _IgnorePointer())
2001-
}
2000+
internal func _arrayReserve(_ minimumCapacity: Int) {
20022001

2003-
internal func _arrayReserve<_Buffer>(
2004-
_ buffer: inout _Buffer, _ minimumCapacity: Int
2005-
) where
2006-
_Buffer : _ArrayBufferProtocol,
2007-
_Buffer.Index == Int {
2002+
let count = self.count
2003+
let requiredCapacity = max(count, minimumCapacity)
20082004

2009-
let count = buffer.count
2010-
let requiredCapacity = max(count, minimumCapacity)
2005+
if _fastPath(
2006+
buffer.requestUniqueMutableBackingBuffer(
2007+
minimumCapacity: requiredCapacity) != nil
2008+
) {
2009+
return
2010+
}
20112011

2012-
if _fastPath(
2013-
buffer.requestUniqueMutableBackingBuffer(
2014-
minimumCapacity: requiredCapacity) != nil
2015-
) {
2016-
return
2012+
var newBuffer = _forceCreateUniqueMutableBuffer(
2013+
newCount: count, requiredCapacity: requiredCapacity)
2014+
_arrayOutOfPlaceUpdate(&newBuffer, count, 0, _IgnorePointer())
20172015
}
2018-
2019-
var newBuffer = buffer._forceCreateUniqueMutableBuffer(
2020-
newCount: count, requiredCapacity: requiredCapacity)
2021-
buffer._arrayOutOfPlaceUpdate(&newBuffer, count, 0, _IgnorePointer())
20222016
}
20232017

20242018
/// Append items from `newItems` to `buffer`.

0 commit comments

Comments
 (0)