mirror of
https://github.com/ziglang/zig.git
synced 2026-01-21 14:55:25 +00:00
ArrayList: add unusedCapacitySlice to the unmanaged API
This function is super nice thank you whoever added it 👍
This commit is contained in:
parent
32edb9b55d
commit
123076ea88
@ -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..];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user