Skip to content

Commit f244420

Browse files
committed
[DNM] revert all changes on Suffix
1 parent 91ff835 commit f244420

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

stdlib/public/core/Sequence.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ extension Sequence {
891891
// Put incoming elements into a ring buffer to save space. Once all
892892
// elements are consumed, reorder the ring buffer and return it.
893893
// This saves memory for sequences particularly longer than `maxLength`.
894-
var ringBuffer = ContiguousArray<Element>()
894+
var ringBuffer: [Element] = []
895895
ringBuffer.reserveCapacity(Swift.min(maxLength, underestimatedCount))
896896

897897
var i = 0
@@ -901,16 +901,20 @@ extension Sequence {
901901
ringBuffer.append(element)
902902
} else {
903903
ringBuffer[i] = element
904-
i = (i + 1) % maxLength
904+
i += 1
905+
i %= maxLength
905906
}
906907
}
907908

908-
if i != ringBuffer.startIndex { // Rotate the array in-place
909-
ringBuffer[0..<i].reverse()
910-
ringBuffer[i..<ringBuffer.endIndex].reverse()
911-
ringBuffer[0..<ringBuffer.endIndex].reverse()
909+
if i != ringBuffer.startIndex {
910+
var rotated: [Element] = []
911+
rotated.reserveCapacity(ringBuffer.count)
912+
rotated += ringBuffer[i..<ringBuffer.endIndex]
913+
rotated += ringBuffer[0..<i]
914+
return rotated
915+
} else {
916+
return ringBuffer
912917
}
913-
return Array(ringBuffer)
914918
}
915919

916920
/// Returns a sequence containing all but the given number of initial

0 commit comments

Comments
 (0)