File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -590,9 +590,10 @@ extension RangeReplaceableCollection {
590
590
public mutating func removeFirst( _ k: Int ) {
591
591
if k == 0 { return }
592
592
_precondition ( k >= 0 , " Number of elements to remove should be non-negative " )
593
- _precondition ( count >= k,
594
- " Can't remove more items from a collection than it has " )
595
- let end = index ( startIndex, offsetBy: k)
593
+ guard let end = index ( startIndex, offsetBy: k, limitedBy: endIndex) else {
594
+ _preconditionFailure (
595
+ " Can't remove more items from a collection than it has " )
596
+ }
596
597
removeSubrange ( startIndex..< end)
597
598
}
598
599
@@ -698,9 +699,11 @@ extension RangeReplaceableCollection where SubSequence == Self {
698
699
public mutating func removeFirst( _ k: Int ) {
699
700
if k == 0 { return }
700
701
_precondition ( k >= 0 , " Number of elements to remove should be non-negative " )
701
- _precondition ( count >= k,
702
- " Can't remove more items from a collection than it contains " )
703
- self = self [ index ( startIndex, offsetBy: k) ..< endIndex]
702
+ guard let idx = index ( startIndex, offsetBy: k, limitedBy: endIndex) else {
703
+ _preconditionFailure (
704
+ " Can't remove more items from a collection than it contains " )
705
+ }
706
+ self = self [ idx..< endIndex]
704
707
}
705
708
}
706
709
You can’t perform that action at this time.
0 commit comments