Skip to content

Commit b9d3e5f

Browse files
authored
Merge pull request #5229 from apple/expression-breakup
2 parents e5f7ef9 + be1f95a commit b9d3e5f

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

stdlib/public/core/Sequence.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -880,13 +880,15 @@ extension Sequence {
880880
ringBuffer.append(element)
881881
} else {
882882
ringBuffer[i] = element
883-
i = ringBuffer.index(after: i) % maxLength
883+
i += 1
884+
i %= maxLength
884885
}
885886
}
886887

887888
if i != ringBuffer.startIndex {
888-
return AnySequence(
889-
[ringBuffer[i..<ringBuffer.endIndex], ringBuffer[0..<i]].joined())
889+
let s0 = ringBuffer[i..<ringBuffer.endIndex]
890+
let s1 = ringBuffer[0..<i]
891+
return AnySequence([s0, s1].joined())
890892
}
891893
return AnySequence(ringBuffer)
892894
}

stdlib/public/core/Slice.swift.gyb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public struct ${Self}<Base : ${BaseRequirements}>
252252
let newSliceCount: IndexDistance =
253253
_base.distance(from: _startIndex, to: subRange.lowerBound)
254254
+ _base.distance(from: subRange.upperBound, to: _endIndex)
255-
+ numericCast(newElements.count)
255+
+ (numericCast(newElements.count) as IndexDistance)
256256
_base.replaceSubrange(subRange, with: newElements)
257257
_startIndex = _base.index(_base.startIndex, offsetBy: sliceOffset)
258258
_endIndex = _base.index(_startIndex, offsetBy: newSliceCount)
@@ -261,7 +261,7 @@ public struct ${Self}<Base : ${BaseRequirements}>
261261
let newSliceCount: IndexDistance =
262262
_base.distance(from: _startIndex, to: subRange.lowerBound)
263263
+ _base.distance(from: subRange.upperBound, to: _endIndex)
264-
+ numericCast(newElements.count)
264+
+ (numericCast(newElements.count) as IndexDistance)
265265
_base.replaceSubrange(subRange, with: newElements)
266266
_startIndex = _base.startIndex
267267
_endIndex = _base.index(_startIndex, offsetBy: newSliceCount)
@@ -270,7 +270,7 @@ public struct ${Self}<Base : ${BaseRequirements}>
270270
let lastValidIndex = _base.index(before: subRange.lowerBound)
271271
let newEndIndexOffset =
272272
_base.distance(from: subRange.upperBound, to: _endIndex)
273-
+ numericCast(newElements.count) + 1
273+
+ (numericCast(newElements.count) as IndexDistance) + 1
274274
_base.replaceSubrange(subRange, with: newElements)
275275
if shouldUpdateStartIndex {
276276
_startIndex = _base.index(after: lastValidIndex)
@@ -318,14 +318,14 @@ public struct ${Self}<Base : ${BaseRequirements}>
318318
let sliceOffset: IndexDistance =
319319
_base.distance(from: _base.startIndex, to: _startIndex)
320320
let newSliceCount: IndexDistance =
321-
count + numericCast(newElements.count)
321+
count + (numericCast(newElements.count) as IndexDistance)
322322
_base.insert(contentsOf: newElements, at: i)
323323
_startIndex = _base.index(_base.startIndex, offsetBy: sliceOffset)
324324
_endIndex = _base.index(_startIndex, offsetBy: newSliceCount)
325325
% else:
326326
if i == _base.startIndex {
327327
let newSliceCount: IndexDistance =
328-
count + numericCast(newElements.count)
328+
count + (numericCast(newElements.count) as IndexDistance)
329329
_base.insert(contentsOf: newElements, at: i)
330330
_startIndex = _base.startIndex
331331
_endIndex = _base.index(_startIndex, offsetBy: newSliceCount)
@@ -334,7 +334,7 @@ public struct ${Self}<Base : ${BaseRequirements}>
334334
let lastValidIndex = _base.index(before: i)
335335
let newEndIndexOffset =
336336
_base.distance(from: i, to: _endIndex)
337-
+ numericCast(newElements.count) + 1
337+
+ (numericCast(newElements.count) as IndexDistance) + 1
338338
_base.insert(contentsOf: newElements, at: i)
339339
if shouldUpdateStartIndex {
340340
_startIndex = _base.index(after: lastValidIndex)

0 commit comments

Comments
 (0)