Skip to content

Commit b0334cb

Browse files
committed
[stdlib] Remove an unnecessary level of Optional. NFC.
1 parent b911fda commit b0334cb

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

stdlib/public/core/Arrays.swift.gyb

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -651,9 +651,8 @@ extension ${Self} : RangeReplaceableCollection, _ArrayProtocol {
651651
@inline(never)
652652
internal mutating func _copyToNewBuffer(oldCount: Int) {
653653
let newCount = oldCount + 1
654-
var newBuffer = Optional(
655-
_forceCreateUniqueMutableBuffer(
656-
&_buffer, countForNewBuffer: oldCount, minNewCapacity: newCount))
654+
var newBuffer = _forceCreateUniqueMutableBuffer(
655+
&_buffer, countForNewBuffer: oldCount, minNewCapacity: newCount)
657656
_arrayOutOfPlaceUpdate(
658657
&_buffer, &newBuffer, oldCount, 0, _IgnorePointer())
659658
}
@@ -952,9 +951,8 @@ internal func _arrayOutOfPlaceReplace<
952951
) {
953952
let growth = insertCount - bounds.count
954953
let newCount = source.count + growth
955-
var newBuffer = Optional(
956-
_forceCreateUniqueMutableBuffer(
957-
&source, newCount: newCount, requiredCapacity: newCount))
954+
var newBuffer = _forceCreateUniqueMutableBuffer(
955+
&source, newCount: newCount, requiredCapacity: newCount)
958956

959957
_arrayOutOfPlaceUpdate(
960958
&source, &newBuffer,
@@ -1128,7 +1126,7 @@ internal func _arrayOutOfPlaceUpdate<
11281126
_Buffer.Index == Int
11291127
>(
11301128
_ source: inout _Buffer,
1131-
_ dest: inout _ContiguousArrayBuffer<_Buffer.Element>?,
1129+
_ dest: inout _ContiguousArrayBuffer<_Buffer.Element>,
11321130
_ headCount: Int, // Count of initial source elements to copy/move
11331131
_ newCount: Int, // Number of new elements to insert
11341132
_ initializeNewElements: Initializer
@@ -1137,12 +1135,12 @@ internal func _arrayOutOfPlaceUpdate<
11371135
_sanityCheck(newCount >= 0)
11381136

11391137
// Count of trailing source elements to copy/move
1140-
let tailCount = dest!.count - headCount - newCount
1138+
let tailCount = dest.count - headCount - newCount
11411139
_sanityCheck(headCount + tailCount <= source.count)
11421140

11431141
let sourceCount = source.count
11441142
let oldCount = sourceCount - headCount - tailCount
1145-
let destStart = dest!.firstElementAddress
1143+
let destStart = dest.firstElementAddress
11461144
let newStart = destStart + headCount
11471145
let newEnd = newStart + newCount
11481146

@@ -1188,7 +1186,7 @@ internal func _arrayOutOfPlaceUpdate<
11881186
let tailEnd = source.endIndex
11891187
source._copyContents(subRange: tailStart..<tailEnd, initializing: newEnd)
11901188
}
1191-
source = _Buffer(dest!, shiftedToStartIndex: source.startIndex)
1189+
source = _Buffer(dest, shiftedToStartIndex: source.startIndex)
11921190
}
11931191

11941192
internal struct _InitializePointer<T> : _PointerFunction {
@@ -1224,9 +1222,8 @@ internal func _outlinedMakeUniqueBuffer<
12241222
return
12251223
}
12261224

1227-
var newBuffer = Optional(
1228-
_forceCreateUniqueMutableBuffer(
1229-
&buffer, newCount: bufferCount, requiredCapacity: bufferCount))
1225+
var newBuffer = _forceCreateUniqueMutableBuffer(
1226+
&buffer, newCount: bufferCount, requiredCapacity: bufferCount)
12301227
_arrayOutOfPlaceUpdate(&buffer, &newBuffer, bufferCount, 0, _IgnorePointer())
12311228
}
12321229

@@ -1245,9 +1242,8 @@ internal func _arrayReserve<
12451242
return
12461243
}
12471244

1248-
var newBuffer = Optional(
1249-
_forceCreateUniqueMutableBuffer(
1250-
&buffer, newCount: count, requiredCapacity: requiredCapacity))
1245+
var newBuffer = _forceCreateUniqueMutableBuffer(
1246+
&buffer, newCount: count, requiredCapacity: requiredCapacity)
12511247
_arrayOutOfPlaceUpdate(&buffer, &newBuffer, count, 0, _IgnorePointer())
12521248
}
12531249

0 commit comments

Comments
 (0)