authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-18 19:35:39-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-18 19:35:39-07:00
log123076ea88a809888692b308ab5bb214dc3a2caf
tree62c853ec54611ae038fd12b1b51911b370079cdc
parent32edb9b55d0e41a58a11e0437149c4a9705c4699

ArrayList: add unusedCapacitySlice to the unmanaged API

This function is super nice thank you whoever added it 👍

1 files changed, 8 insertions(+), 0 deletions(-)

lib/std/array_list.zig+8
......@@ -780,6 +780,14 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
780780 pub fn allocatedSlice(self: Self) Slice {
781781 return self.items.ptr[0..self.capacity];
782782 }
783
784 /// Returns a slice of only the extra capacity after items.
785 /// This can be useful for writing directly into an ArrayList.
786 /// Note that such an operation must be followed up with a direct
787 /// modification of `self.items.len`.
788 pub fn unusedCapacitySlice(self: Self) Slice {
789 return self.allocatedSlice()[self.items.len..];
790 }
783791 };
784792}
785793