Skip to content

Commit 099ecbe

Browse files
authored
Improve performance of Collection.removeFirst(_:) where Self == SubSequence
1 parent 1b98ca3 commit 099ecbe

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

stdlib/public/core/Collection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,7 @@ extension Collection where SubSequence == Self {
16641664
public mutating func removeFirst(_ k: Int) {
16651665
if k == 0 { return }
16661666
_precondition(k >= 0, "Number of elements to remove should be non-negative")
1667-
_precondition(count >= k,
1667+
_precondition(index(startIndex, offsetBy: k, limitedBy: endIndex) != nil,
16681668
"Can't remove more items from a collection than it contains")
16691669
self = self[index(startIndex, offsetBy: k)..<endIndex]
16701670
}

0 commit comments

Comments
 (0)