| ... | ... | @@ -51,7 +51,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 51 | 51 | return if (alignment) |a| ([:s]align(a) T) else [:s]T; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | | /// Deinitialize with `deinit`. |
| 54 | /// Deinitialize with `deinit` or use `toOwnedSlice`. |
| 55 | 55 | pub fn init(allocator: Allocator) Self { |
| 56 | 56 | return Self{ |
| 57 | 57 | .items = &[_]T{}, |
| ... | ... | @@ -62,7 +62,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 62 | 62 | |
| 63 | 63 | /// Initialize with capacity to hold at least `num` elements. |
| 64 | 64 | /// The resulting capacity is likely to be equal to `num`. |
| 65 | | /// Deinitialize with `deinit`. |
| 65 | /// Deinitialize with `deinit` or use `toOwnedSlice`. |
| 66 | 66 | pub fn initCapacity(allocator: Allocator, num: usize) Allocator.Error!Self { |
| 67 | 67 | var self = Self.init(allocator); |
| 68 | 68 | try self.ensureTotalCapacityPrecise(num); |
| ... | ... | @@ -78,7 +78,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 78 | 78 | |
| 79 | 79 | /// ArrayList takes ownership of the passed in slice. The slice must have been |
| 80 | 80 | /// allocated with `allocator`. |
| 81 | | /// Deinitialize with `deinit`. |
| 81 | /// Deinitialize with `deinit` or use `toOwnedSlice`. |
| 82 | 82 | pub fn fromOwnedSlice(allocator: Allocator, slice: Slice) Self { |
| 83 | 83 | return Self{ |
| 84 | 84 | .items = slice, |
| ... | ... | @@ -97,8 +97,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | /// The caller owns the returned memory. Empties this ArrayList, |
| 100 | | /// however its capacity may or may not be cleared and deinit() is |
| 101 | | /// still required to clean up its memory. |
| 100 | /// Its capacity is cleared, making deinit() safe but unnecessary to call. |
| 102 | 101 | pub fn toOwnedSlice(self: *Self) Allocator.Error!Slice { |
| 103 | 102 | const allocator = self.allocator; |
| 104 | 103 | |
| ... | ... | @@ -112,7 +111,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 112 | 111 | const new_memory = try allocator.alignedAlloc(T, alignment, self.items.len); |
| 113 | 112 | mem.copy(T, new_memory, self.items); |
| 114 | 113 | @memset(@ptrCast([*]u8, self.items.ptr), undefined, self.items.len * @sizeOf(T)); |
| 115 | | self.items.len = 0; |
| 114 | self.clearAndFree(); |
| 116 | 115 | return new_memory; |
| 117 | 116 | } |
| 118 | 117 | |
| ... | ... | @@ -475,7 +474,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 475 | 474 | /// An ArrayList, but the allocator is passed as a parameter to the relevant functions |
| 476 | 475 | /// rather than stored in the struct itself. The same allocator **must** be used throughout |
| 477 | 476 | /// the entire lifetime of an ArrayListUnmanaged. Initialize directly or with |
| 478 | | /// `initCapacity`, and deinitialize with `deinit`. |
| 477 | /// `initCapacity`, and deinitialize with `deinit` or use `toOwnedSlice`. |
| 479 | 478 | pub fn ArrayListUnmanaged(comptime T: type) type { |
| 480 | 479 | return ArrayListAlignedUnmanaged(T, null); |
| 481 | 480 | } |
| ... | ... | @@ -483,7 +482,7 @@ pub fn ArrayListUnmanaged(comptime T: type) type { |
| 483 | 482 | /// An ArrayListAligned, but the allocator is passed as a parameter to the relevant |
| 484 | 483 | /// functions rather than stored in the struct itself. The same allocator **must** |
| 485 | 484 | /// be used throughout the entire lifetime of an ArrayListAlignedUnmanaged. |
| 486 | | /// Initialize directly or with `initCapacity`, and deinitialize with `deinit`. |
| 485 | /// Initialize directly or with `initCapacity`, and deinitialize with `deinit` or use `toOwnedSlice`. |
| 487 | 486 | pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) type { |
| 488 | 487 | if (alignment) |a| { |
| 489 | 488 | if (a == @alignOf(T)) { |
| ... | ... | @@ -514,7 +513,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 514 | 513 | |
| 515 | 514 | /// Initialize with capacity to hold at least num elements. |
| 516 | 515 | /// The resulting capacity is likely to be equal to `num`. |
| 517 | | /// Deinitialize with `deinit`. |
| 516 | /// Deinitialize with `deinit` or use `toOwnedSlice`. |
| 518 | 517 | pub fn initCapacity(allocator: Allocator, num: usize) Allocator.Error!Self { |
| 519 | 518 | var self = Self{}; |
| 520 | 519 | try self.ensureTotalCapacityPrecise(allocator, num); |
| ... | ... | @@ -533,9 +532,8 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 533 | 532 | return .{ .items = self.items, .capacity = self.capacity, .allocator = allocator }; |
| 534 | 533 | } |
| 535 | 534 | |
| 536 | | /// The caller owns the returned memory. Empties this ArrayList, |
| 537 | | /// however its capacity may or may not be cleared and deinit() is |
| 538 | | /// still required to clean up its memory. |
| 535 | /// The caller owns the returned memory. Empties this ArrayList. |
| 536 | /// Its capacity is cleared, making deinit() safe but unnecessary to call. |
| 539 | 537 | pub fn toOwnedSlice(self: *Self, allocator: Allocator) Allocator.Error!Slice { |
| 540 | 538 | const old_memory = self.allocatedSlice(); |
| 541 | 539 | if (allocator.resize(old_memory, self.items.len)) { |
| ... | ... | @@ -547,7 +545,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 547 | 545 | const new_memory = try allocator.alignedAlloc(T, alignment, self.items.len); |
| 548 | 546 | mem.copy(T, new_memory, self.items); |
| 549 | 547 | @memset(@ptrCast([*]u8, self.items.ptr), undefined, self.items.len * @sizeOf(T)); |
| 550 | | self.items.len = 0; |
| 548 | self.clearAndFree(allocator); |
| 551 | 549 | return new_memory; |
| 552 | 550 | } |
| 553 | 551 | |