mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
std.ArrayList: add clearRetainingCapacity and clearAndFree
This commit is contained in:
parent
5d7f2697de
commit
c714a3250f
1 changed files with 24 additions and 0 deletions
|
|
@ -294,6 +294,18 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
|
|||
self.items.len = new_len;
|
||||
}
|
||||
|
||||
/// Invalidates all element pointers.
|
||||
pub fn clearRetainingCapacity(self: *Self) void {
|
||||
self.items.len = 0;
|
||||
}
|
||||
|
||||
/// Invalidates all element pointers.
|
||||
pub fn clearAndFree(self: *Self) void {
|
||||
self.allocator.free(self.allocatedSlice());
|
||||
self.items.len = 0;
|
||||
self.capacity = 0;
|
||||
}
|
||||
|
||||
/// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`.
|
||||
pub const ensureCapacity = ensureTotalCapacity;
|
||||
|
||||
|
|
@ -611,6 +623,18 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
|
|||
self.items.len = new_len;
|
||||
}
|
||||
|
||||
/// Invalidates all element pointers.
|
||||
pub fn clearRetainingCapacity(self: *Self) void {
|
||||
self.items.len = 0;
|
||||
}
|
||||
|
||||
/// Invalidates all element pointers.
|
||||
pub fn clearAndFree(self: *Self, allocator: *Allocator) void {
|
||||
allocator.free(self.allocatedSlice());
|
||||
self.items.len = 0;
|
||||
self.capacity = 0;
|
||||
}
|
||||
|
||||
/// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`.
|
||||
pub const ensureCapacity = ensureTotalCapacity;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue