diff options
| author | Bas <BarabasGitHub@users.noreply.github.com> | 2020-09-08 11:56:59 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-08 11:56:59 +0200 |
| commit | 4a6ca735d9b3d466aba37c4488c1235b06a0bc84 (patch) | |
| tree | 10ef029ccaefe15c5152c1512a952ca6fdb01358 /lib/std/array_list.zig | |
| parent | 0a40a61548ad9f666ed5300a8910f9040cc1390b (diff) | |
| parent | 389c26025283edef2206d19d9ad1ddc41e98f007 (diff) | |
| download | zig-4a6ca735d9b3d466aba37c4488c1235b06a0bc84.tar.gz zig-4a6ca735d9b3d466aba37c4488c1235b06a0bc84.zip | |
Merge branch 'master' into improve-windows-networking
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; } |
