| ... | @@ -46,7 +46,11 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { | ... | @@ -46,7 +46,11 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 46 | /// Deinitialize with `deinit` or use `toOwnedSlice`. | 46 | /// Deinitialize with `deinit` or use `toOwnedSlice`. |
| 47 | pub fn initCapacity(allocator: *Allocator, num: usize) !Self { | 47 | pub fn initCapacity(allocator: *Allocator, num: usize) !Self { |
| 48 | var self = Self.init(allocator); | 48 | var self = Self.init(allocator); |
| 49 | try self.ensureCapacity(num); | 49 | |
| | 50 | const new_memory = try self.allocator.allocAdvanced(T, alignment, num, .at_least); |
| | 51 | self.items.ptr = new_memory.ptr; |
| | 52 | self.capacity = new_memory.len; |
| | 53 | |
| 50 | return self; | 54 | return self; |
| 51 | } | 55 | } |
| 52 | | 56 | |
| ... | @@ -366,7 +370,11 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ | ... | @@ -366,7 +370,11 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 366 | /// Deinitialize with `deinit` or use `toOwnedSlice`. | 370 | /// Deinitialize with `deinit` or use `toOwnedSlice`. |
| 367 | pub fn initCapacity(allocator: *Allocator, num: usize) !Self { | 371 | pub fn initCapacity(allocator: *Allocator, num: usize) !Self { |
| 368 | var self = Self{}; | 372 | var self = Self{}; |
| 369 | try self.ensureCapacity(allocator, num); | 373 | |
| | 374 | const new_memory = try self.allocator.allocAdvanced(T, alignment, num, .at_least); |
| | 375 | self.items.ptr = new_memory.ptr; |
| | 376 | self.capacity = new_memory.len; |
| | 377 | |
| 370 | return self; | 378 | return self; |
| 371 | } | 379 | } |
| 372 | | 380 | |