diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-09-07 11:17:42 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-09-07 11:17:42 -0700 |
| commit | 52b8239a22aa37fe3914427cd4e2905231769e59 (patch) | |
| tree | cd60ca825c14b5befbcddf674bdb7d3feda81d23 /lib/std/array_list.zig | |
| parent | 338f155a02b72117ff710f72c8578e7d2f8eb296 (diff) | |
| parent | 533bfc68bf8b4ad7ffbe5814a622f200dc345b69 (diff) | |
| download | zig-52b8239a22aa37fe3914427cd4e2905231769e59.tar.gz zig-52b8239a22aa37fe3914427cd4e2905231769e59.zip | |
Merge remote-tracking branch 'origin/master' into llvm11
Diffstat (limited to 'lib/std/array_list.zig')
| -rw-r--r-- | lib/std/array_list.zig | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig index a7432a30ae..f298d14631 100644 --- a/lib/std/array_list.zig +++ b/lib/std/array_list.zig @@ -46,7 +46,11 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { /// Deinitialize with `deinit` or use `toOwnedSlice`. pub fn initCapacity(allocator: *Allocator, num: usize) !Self { var self = Self.init(allocator); - try self.ensureCapacity(num); + + const new_memory = try self.allocator.allocAdvanced(T, alignment, num, .at_least); + self.items.ptr = new_memory.ptr; + self.capacity = new_memory.len; + return self; } @@ -366,7 +370,11 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ /// Deinitialize with `deinit` or use `toOwnedSlice`. pub fn initCapacity(allocator: *Allocator, num: usize) !Self { var self = Self{}; - try self.ensureCapacity(allocator, num); + + const new_memory = try self.allocator.allocAdvanced(T, alignment, num, .at_least); + self.items.ptr = new_memory.ptr; + self.capacity = new_memory.len; + return self; } |
