[BasicContainers] RigidArray, UniqueArray: “precisely once” → “at most once”

Loosen guarantees about how many times closure arguments are getting called, so that e.g. insertions of zero items do not necessarily need to call their callback with an empty OutputSpan.

(For these array types we can reinstate the guarantee later, if it turns out to be important/useful. However, the generalized primitives will need to allow their callbacks to get called an arbitrary number of times, and it seems useful to establish that (at least partially) with these simple array types too.)
This commit is contained in:
Karoy Lorentey committed 2026-02-04 10:09:00 -08:00
1 parent 99da8a72e0
commit b768d22393
11 files changed
+18 -14

No files matched your search

@@ -45,7 +45,7 @@ extension UniqueArray where Element: ~Copyable {
///
/// - Parameters
/// - count: The number of items to append to the array.
/// - body: A callback that gets called precisely once to directly
/// - body: A callback that gets called at most once to directly
/// populate newly reserved storage within the array. The function
/// is allowed to initialize fewer than `count` items. The array is
/// appended however many items the callback adds to the output span
@@ -38,7 +38,7 @@ extension UniqueArray where Element: ~Copyable {
///
/// - Parameters:
/// - capacity: The storage capacity of the new array.
/// - body: A callback that gets called precisely once to directly
/// - body: A callback that gets called at most once to directly
/// populate newly reserved storage within the array. The function
/// is allowed to add fewer than `capacity` items. The array is
/// initialized with however many items the callback adds to the
@@ -62,7 +62,7 @@ extension UniqueArray where Element: ~Copyable {
/// - count: The number of items to insert into the array.
/// - index: The position at which to insert the new items.
/// `index` must be a valid index in the array.
/// - body: A callback that gets called precisely once to directly
/// - body: A callback that gets called at most once to directly
/// populate newly reserved storage within the array. The function
/// is called with an empty output span of capacity matching the
/// supplied count, and it must fully populate it before returning.
@@ -43,7 +43,7 @@ extension UniqueArray where Element: ~Copyable {
/// - subrange: The subrange of the array to replace. The bounds of
/// the range must be valid indices in the array.
/// - newCount: the number of items to replace the old subrange.
/// - body: A callback that gets called precisely once to directly
/// - body: A callback that gets called at most once to directly
/// populate newly reserved storage within the array. The function
/// is called with an empty output span of capacity `newCount`,
/// and it must fully populate it before returning.
@@ -128,7 +128,7 @@ extension UniqueArray where Element: ~Copyable {
extension UniqueArray where Element: ~Copyable {
/// Arbitrarily edit the storage underlying this array by invoking a
/// user-supplied closure with a mutable `OutputSpan` view over it.
/// This method calls its function argument precisely once, allowing it to
/// This method calls its function argument at most once, allowing it to
/// arbitrarily modify the contents of the output span it is given.
/// The argument is free to add, remove or reorder any items; however,
/// it is not allowed to replace the span or change its capacity.
@@ -139,7 +139,7 @@ extension UniqueArray where Element: ~Copyable {
///
/// - Parameter body: A function that edits the contents of this array through
/// an `OutputSpan` argument. This method invokes this function
/// precisely once.
/// at most once.
/// - Returns: This method returns the result of its function argument.
/// - Complexity: Adds O(1) overhead to the complexity of the function
/// argument.