Array, Deque types: Introduce _checkItemIndex, _checkValidIndex, _checkValidBounds

This commit is contained in:
Karoy Lorentey committed 2026-02-16 17:05:36 -08:00
1 parent ac7a8bf61b
commit 621374557c
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(