| ... | ... | @@ -3,6 +3,7 @@ const debug = std.debug; |
| 3 | 3 | const assert = debug.assert; |
| 4 | 4 | const testing = std.testing; |
| 5 | 5 | const mem = std.mem; |
| 6 | const math = std.math; |
| 6 | 7 | const Allocator = mem.Allocator; |
| 7 | 8 | |
| 8 | 9 | /// A contiguous, growable list of items in memory. |
| ... | ... | @@ -330,17 +331,17 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 330 | 331 | /// Invalidates pointers if additional memory is needed. |
| 331 | 332 | pub fn ensureTotalCapacity(self: *Self, new_capacity: usize) Allocator.Error!void { |
| 332 | 333 | if (@sizeOf(T) > 0) { |
| 333 | | var better_capacity = self.capacity; |
| 334 | | if (better_capacity >= new_capacity) return; |
| 334 | if (self.capacity >= new_capacity) return; |
| 335 | 335 | |
| 336 | var better_capacity = self.capacity; |
| 336 | 337 | while (true) { |
| 337 | | better_capacity += better_capacity / 2 + 8; |
| 338 | better_capacity +|= better_capacity / 2 + 8; |
| 338 | 339 | if (better_capacity >= new_capacity) break; |
| 339 | 340 | } |
| 340 | 341 | |
| 341 | 342 | return self.ensureTotalCapacityPrecise(better_capacity); |
| 342 | 343 | } else { |
| 343 | | self.capacity = std.math.maxInt(usize); |
| 344 | self.capacity = math.maxInt(usize); |
| 344 | 345 | } |
| 345 | 346 | } |
| 346 | 347 | |
| ... | ... | @@ -357,7 +358,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 357 | 358 | self.items.ptr = new_memory.ptr; |
| 358 | 359 | self.capacity = new_memory.len; |
| 359 | 360 | } else { |
| 360 | | self.capacity = std.math.maxInt(usize); |
| 361 | self.capacity = math.maxInt(usize); |
| 361 | 362 | } |
| 362 | 363 | } |
| 363 | 364 | |
| ... | ... | @@ -725,11 +726,11 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 725 | 726 | /// Modify the array so that it can hold at least `new_capacity` items. |
| 726 | 727 | /// Invalidates pointers if additional memory is needed. |
| 727 | 728 | pub fn ensureTotalCapacity(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void { |
| 728 | | var better_capacity = self.capacity; |
| 729 | | if (better_capacity >= new_capacity) return; |
| 729 | if (self.capacity >= new_capacity) return; |
| 730 | 730 | |
| 731 | var better_capacity = self.capacity; |
| 731 | 732 | while (true) { |
| 732 | | better_capacity += better_capacity / 2 + 8; |
| 733 | better_capacity +|= better_capacity / 2 + 8; |
| 733 | 734 | if (better_capacity >= new_capacity) break; |
| 734 | 735 | } |
| 735 | 736 | |