aboutsummaryrefslogtreecommitdiff
path: root/lib/std/array_list.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-02-18 19:35:39 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-02-18 19:35:39 -0700
commit123076ea88a809888692b308ab5bb214dc3a2caf (patch)
tree62c853ec54611ae038fd12b1b51911b370079cdc /lib/std/array_list.zig
parent32edb9b55d0e41a58a11e0437149c4a9705c4699 (diff)
downloadzig-123076ea88a809888692b308ab5bb214dc3a2caf.tar.gz
zig-123076ea88a809888692b308ab5bb214dc3a2caf.zip
ArrayList: add unusedCapacitySlice to the unmanaged API
This function is super nice thank you whoever added it 👍
Diffstat (limited to 'lib/std/array_list.zig')
-rw-r--r--lib/std/array_list.zig8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig
index 76e73a49b5..eb726f4dfa 100644
--- a/lib/std/array_list.zig
+++ b/lib/std/array_list.zig
@@ -780,6 +780,14 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
pub fn allocatedSlice(self: Self) Slice {
return self.items.ptr[0..self.capacity];
}
+
+ /// Returns a slice of only the extra capacity after items.
+ /// This can be useful for writing directly into an ArrayList.
+ /// Note that such an operation must be followed up with a direct
+ /// modification of `self.items.len`.
+ pub fn unusedCapacitySlice(self: Self) Slice {
+ return self.allocatedSlice()[self.items.len..];
+ }
};
}