mirror of
https://github.com/apple/swift-collections
synced 2026-11-25 04:37:48 +00:00
Array, Deque types: Introduce _checkItemIndex, _checkValidIndex, _checkValidBounds
This commit is contained in:
16 files changed
+83
-58
No files matched your search
@@ -65,9 +65,7 @@ extension UniqueArray where Element: ~Copyable {
|
||||
addingCount newItemCount: Int,
|
||||
initializingWith initializer: (inout OutputSpan<Element>) throws(E) -> Void
|
||||
) throws(E) -> Void {
|
||||
precondition(
|
||||
subrange.lowerBound >= 0 && subrange.upperBound <= self.count,
|
||||
"Index range out of bounds")
|
||||
_storage._checkValidBounds(subrange)
|
||||
precondition(newItemCount >= 0, "Cannot add a negative number of items")
|
||||
// FIXME: Avoid moving the subsequent elements twice on resize.
|
||||
_ensureFreeCapacity(newItemCount - subrange.count)
|
||||
@@ -136,9 +134,7 @@ extension UniqueArray where Element: ~Copyable {
|
||||
addingCount newItemCount: Int,
|
||||
initializingWith initializer: (inout OutputSpan<Element>) throws(E) -> Void
|
||||
) throws(E) -> Void {
|
||||
precondition(
|
||||
subrange.lowerBound >= 0 && subrange.upperBound <= self.count,
|
||||
"Index range out of bounds")
|
||||
_storage._checkValidBounds(subrange)
|
||||
precondition(newItemCount >= 0, "Cannot add a negative number of items")
|
||||
_ensureFreeCapacity(newItemCount - subrange.count)
|
||||
try _storage._uncheckedReplace(
|
||||
|
||||
Reference in new issue
Block a user