| ... | ... | @@ -50,19 +50,19 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /// Deinitialize with `deinit` or use `toOwnedSlice`. |
| 53 | | pub fn init(allocator: Allocator) Self { |
| 53 | pub fn init(gpa: Allocator) Self { |
| 54 | 54 | return Self{ |
| 55 | 55 | .items = &[_]T{}, |
| 56 | 56 | .capacity = 0, |
| 57 | | .allocator = allocator, |
| 57 | .allocator = gpa, |
| 58 | 58 | }; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /// Initialize with capacity to hold `num` elements. |
| 62 | 62 | /// The resulting capacity will equal `num` exactly. |
| 63 | 63 | /// Deinitialize with `deinit` or use `toOwnedSlice`. |
| 64 | | pub fn initCapacity(allocator: Allocator, num: usize) Allocator.Error!Self { |
| 65 | | var self = Self.init(allocator); |
| 64 | pub fn initCapacity(gpa: Allocator, num: usize) Allocator.Error!Self { |
| 65 | var self = Self.init(gpa); |
| 66 | 66 | try self.ensureTotalCapacityPrecise(num); |
| 67 | 67 | return self; |
| 68 | 68 | } |
| ... | ... | @@ -75,24 +75,24 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /// ArrayList takes ownership of the passed in slice. The slice must have been |
| 78 | | /// allocated with `allocator`. |
| 78 | /// allocated with `gpa`. |
| 79 | 79 | /// Deinitialize with `deinit` or use `toOwnedSlice`. |
| 80 | | pub fn fromOwnedSlice(allocator: Allocator, slice: Slice) Self { |
| 80 | pub fn fromOwnedSlice(gpa: Allocator, slice: Slice) Self { |
| 81 | 81 | return Self{ |
| 82 | 82 | .items = slice, |
| 83 | 83 | .capacity = slice.len, |
| 84 | | .allocator = allocator, |
| 84 | .allocator = gpa, |
| 85 | 85 | }; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /// ArrayList takes ownership of the passed in slice. The slice must have been |
| 89 | | /// allocated with `allocator`. |
| 89 | /// allocated with `gpa`. |
| 90 | 90 | /// Deinitialize with `deinit` or use `toOwnedSlice`. |
| 91 | | pub fn fromOwnedSliceSentinel(allocator: Allocator, comptime sentinel: T, slice: [:sentinel]T) Self { |
| 91 | pub fn fromOwnedSliceSentinel(gpa: Allocator, comptime sentinel: T, slice: [:sentinel]T) Self { |
| 92 | 92 | return Self{ |
| 93 | 93 | .items = slice, |
| 94 | 94 | .capacity = slice.len + 1, |
| 95 | | .allocator = allocator, |
| 95 | .allocator = gpa, |
| 96 | 96 | }; |
| 97 | 97 | } |
| 98 | 98 | |
| ... | ... | @@ -646,9 +646,9 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 646 | 646 | /// Initialize with capacity to hold `num` elements. |
| 647 | 647 | /// The resulting capacity will equal `num` exactly. |
| 648 | 648 | /// Deinitialize with `deinit` or use `toOwnedSlice`. |
| 649 | | pub fn initCapacity(allocator: Allocator, num: usize) Allocator.Error!Self { |
| 649 | pub fn initCapacity(gpa: Allocator, num: usize) Allocator.Error!Self { |
| 650 | 650 | var self = Self{}; |
| 651 | | try self.ensureTotalCapacityPrecise(allocator, num); |
| 651 | try self.ensureTotalCapacityPrecise(gpa, num); |
| 652 | 652 | return self; |
| 653 | 653 | } |
| 654 | 654 | |
| ... | ... | @@ -664,19 +664,18 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 664 | 664 | } |
| 665 | 665 | |
| 666 | 666 | /// Release all allocated memory. |
| 667 | | pub fn deinit(self: *Self, allocator: Allocator) void { |
| 668 | | allocator.free(self.allocatedSlice()); |
| 667 | pub fn deinit(self: *Self, gpa: Allocator) void { |
| 668 | gpa.free(self.allocatedSlice()); |
| 669 | 669 | self.* = undefined; |
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | /// Convert this list into an analogous memory-managed one. |
| 673 | 673 | /// The returned list has ownership of the underlying memory. |
| 674 | | pub fn toManaged(self: *Self, allocator: Allocator) ArrayListAligned(T, alignment) { |
| 675 | | return .{ .items = self.items, .capacity = self.capacity, .allocator = allocator }; |
| 674 | pub fn toManaged(self: *Self, gpa: Allocator) ArrayListAligned(T, alignment) { |
| 675 | return .{ .items = self.items, .capacity = self.capacity, .allocator = gpa }; |
| 676 | 676 | } |
| 677 | 677 | |
| 678 | | /// ArrayListUnmanaged takes ownership of the passed in slice. The slice must have been |
| 679 | | /// allocated with `allocator`. |
| 678 | /// ArrayListUnmanaged takes ownership of the passed in slice. |
| 680 | 679 | /// Deinitialize with `deinit` or use `toOwnedSlice`. |
| 681 | 680 | pub fn fromOwnedSlice(slice: Slice) Self { |
| 682 | 681 | return Self{ |
| ... | ... | @@ -685,8 +684,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 685 | 684 | }; |
| 686 | 685 | } |
| 687 | 686 | |
| 688 | | /// ArrayListUnmanaged takes ownership of the passed in slice. The slice must have been |
| 689 | | /// allocated with `allocator`. |
| 687 | /// ArrayListUnmanaged takes ownership of the passed in slice. |
| 690 | 688 | /// Deinitialize with `deinit` or use `toOwnedSlice`. |
| 691 | 689 | pub fn fromOwnedSliceSentinel(comptime sentinel: T, slice: [:sentinel]T) Self { |
| 692 | 690 | return Self{ |
| ... | ... | @@ -697,31 +695,31 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 697 | 695 | |
| 698 | 696 | /// The caller owns the returned memory. Empties this ArrayList. |
| 699 | 697 | /// Its capacity is cleared, making deinit() safe but unnecessary to call. |
| 700 | | pub fn toOwnedSlice(self: *Self, allocator: Allocator) Allocator.Error!Slice { |
| 698 | pub fn toOwnedSlice(self: *Self, gpa: Allocator) Allocator.Error!Slice { |
| 701 | 699 | const old_memory = self.allocatedSlice(); |
| 702 | | if (allocator.remap(old_memory, self.items.len)) |new_items| { |
| 700 | if (gpa.remap(old_memory, self.items.len)) |new_items| { |
| 703 | 701 | self.* = .empty; |
| 704 | 702 | return new_items; |
| 705 | 703 | } |
| 706 | 704 | |
| 707 | | const new_memory = try allocator.alignedAlloc(T, alignment, self.items.len); |
| 705 | const new_memory = try gpa.alignedAlloc(T, alignment, self.items.len); |
| 708 | 706 | @memcpy(new_memory, self.items); |
| 709 | | self.clearAndFree(allocator); |
| 707 | self.clearAndFree(gpa); |
| 710 | 708 | return new_memory; |
| 711 | 709 | } |
| 712 | 710 | |
| 713 | 711 | /// The caller owns the returned memory. ArrayList becomes empty. |
| 714 | | pub fn toOwnedSliceSentinel(self: *Self, allocator: Allocator, comptime sentinel: T) Allocator.Error!SentinelSlice(sentinel) { |
| 712 | pub fn toOwnedSliceSentinel(self: *Self, gpa: Allocator, comptime sentinel: T) Allocator.Error!SentinelSlice(sentinel) { |
| 715 | 713 | // This addition can never overflow because `self.items` can never occupy the whole address space |
| 716 | | try self.ensureTotalCapacityPrecise(allocator, self.items.len + 1); |
| 714 | try self.ensureTotalCapacityPrecise(gpa, self.items.len + 1); |
| 717 | 715 | self.appendAssumeCapacity(sentinel); |
| 718 | | const result = try self.toOwnedSlice(allocator); |
| 716 | const result = try self.toOwnedSlice(gpa); |
| 719 | 717 | return result[0 .. result.len - 1 :sentinel]; |
| 720 | 718 | } |
| 721 | 719 | |
| 722 | 720 | /// Creates a copy of this ArrayList. |
| 723 | | pub fn clone(self: Self, allocator: Allocator) Allocator.Error!Self { |
| 724 | | var cloned = try Self.initCapacity(allocator, self.capacity); |
| 721 | pub fn clone(self: Self, gpa: Allocator) Allocator.Error!Self { |
| 722 | var cloned = try Self.initCapacity(gpa, self.capacity); |
| 725 | 723 | cloned.appendSliceAssumeCapacity(self.items); |
| 726 | 724 | return cloned; |
| 727 | 725 | } |
| ... | ... | @@ -731,8 +729,8 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 731 | 729 | /// This operation is O(N). |
| 732 | 730 | /// Invalidates element pointers if additional memory is needed. |
| 733 | 731 | /// Asserts that the index is in bounds or equal to the length. |
| 734 | | pub fn insert(self: *Self, allocator: Allocator, i: usize, item: T) Allocator.Error!void { |
| 735 | | const dst = try self.addManyAt(allocator, i, 1); |
| 732 | pub fn insert(self: *Self, gpa: Allocator, i: usize, item: T) Allocator.Error!void { |
| 733 | const dst = try self.addManyAt(gpa, i, 1); |
| 736 | 734 | dst[0] = item; |
| 737 | 735 | } |
| 738 | 736 | |
| ... | ... | @@ -759,11 +757,11 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 759 | 757 | /// Asserts that the index is in bounds or equal to the length. |
| 760 | 758 | pub fn addManyAt( |
| 761 | 759 | self: *Self, |
| 762 | | allocator: Allocator, |
| 760 | gpa: Allocator, |
| 763 | 761 | index: usize, |
| 764 | 762 | count: usize, |
| 765 | 763 | ) Allocator.Error![]T { |
| 766 | | var managed = self.toManaged(allocator); |
| 764 | var managed = self.toManaged(gpa); |
| 767 | 765 | defer self.* = managed.moveToUnmanaged(); |
| 768 | 766 | return managed.addManyAt(index, count); |
| 769 | 767 | } |
| ... | ... | @@ -795,12 +793,12 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 795 | 793 | /// Asserts that the index is in bounds or equal to the length. |
| 796 | 794 | pub fn insertSlice( |
| 797 | 795 | self: *Self, |
| 798 | | allocator: Allocator, |
| 796 | gpa: Allocator, |
| 799 | 797 | index: usize, |
| 800 | 798 | items: []const T, |
| 801 | 799 | ) Allocator.Error!void { |
| 802 | 800 | const dst = try self.addManyAt( |
| 803 | | allocator, |
| 801 | gpa, |
| 804 | 802 | index, |
| 805 | 803 | items.len, |
| 806 | 804 | ); |
| ... | ... | @@ -812,7 +810,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 812 | 810 | /// Asserts that the range is in bounds. |
| 813 | 811 | pub fn replaceRange( |
| 814 | 812 | self: *Self, |
| 815 | | allocator: Allocator, |
| 813 | gpa: Allocator, |
| 816 | 814 | start: usize, |
| 817 | 815 | len: usize, |
| 818 | 816 | new_items: []const T, |
| ... | ... | @@ -823,7 +821,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 823 | 821 | const first = new_items[0..range.len]; |
| 824 | 822 | const rest = new_items[range.len..]; |
| 825 | 823 | @memcpy(range[0..first.len], first); |
| 826 | | try self.insertSlice(allocator, after_range, rest); |
| 824 | try self.insertSlice(gpa, after_range, rest); |
| 827 | 825 | } else { |
| 828 | 826 | self.replaceRangeAssumeCapacity(start, len, new_items); |
| 829 | 827 | } |
| ... | ... | @@ -859,8 +857,8 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 859 | 857 | |
| 860 | 858 | /// Extend the list by 1 element. Allocates more memory as necessary. |
| 861 | 859 | /// Invalidates element pointers if additional memory is needed. |
| 862 | | pub fn append(self: *Self, allocator: Allocator, item: T) Allocator.Error!void { |
| 863 | | const new_item_ptr = try self.addOne(allocator); |
| 860 | pub fn append(self: *Self, gpa: Allocator, item: T) Allocator.Error!void { |
| 861 | const new_item_ptr = try self.addOne(gpa); |
| 864 | 862 | new_item_ptr.* = item; |
| 865 | 863 | } |
| 866 | 864 | |
| ... | ... | @@ -899,8 +897,8 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 899 | 897 | /// Append the slice of items to the list. Allocates more |
| 900 | 898 | /// memory as necessary. |
| 901 | 899 | /// Invalidates element pointers if additional memory is needed. |
| 902 | | pub fn appendSlice(self: *Self, allocator: Allocator, items: []const T) Allocator.Error!void { |
| 903 | | try self.ensureUnusedCapacity(allocator, items.len); |
| 900 | pub fn appendSlice(self: *Self, gpa: Allocator, items: []const T) Allocator.Error!void { |
| 901 | try self.ensureUnusedCapacity(gpa, items.len); |
| 904 | 902 | self.appendSliceAssumeCapacity(items); |
| 905 | 903 | } |
| 906 | 904 | |
| ... | ... | @@ -918,8 +916,8 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 918 | 916 | /// memory as necessary. Only call this function if a call to `appendSlice` instead would |
| 919 | 917 | /// be a compile error. |
| 920 | 918 | /// Invalidates element pointers if additional memory is needed. |
| 921 | | pub fn appendUnalignedSlice(self: *Self, allocator: Allocator, items: []align(1) const T) Allocator.Error!void { |
| 922 | | try self.ensureUnusedCapacity(allocator, items.len); |
| 919 | pub fn appendUnalignedSlice(self: *Self, gpa: Allocator, items: []align(1) const T) Allocator.Error!void { |
| 920 | try self.ensureUnusedCapacity(gpa, items.len); |
| 923 | 921 | self.appendUnalignedSliceAssumeCapacity(items); |
| 924 | 922 | } |
| 925 | 923 | |
| ... | ... | @@ -947,8 +945,8 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 947 | 945 | std.io.Writer(WriterContext, Allocator.Error, appendWrite); |
| 948 | 946 | |
| 949 | 947 | /// Initializes a Writer which will append to the list. |
| 950 | | pub fn writer(self: *Self, allocator: Allocator) Writer { |
| 951 | | return .{ .context = .{ .self = self, .allocator = allocator } }; |
| 948 | pub fn writer(self: *Self, gpa: Allocator) Writer { |
| 949 | return .{ .context = .{ .self = self, .allocator = gpa } }; |
| 952 | 950 | } |
| 953 | 951 | |
| 954 | 952 | /// Same as `append` except it returns the number of bytes written, |
| ... | ... | @@ -983,9 +981,9 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 983 | 981 | /// Invalidates element pointers if additional memory is needed. |
| 984 | 982 | /// The function is inline so that a comptime-known `value` parameter will |
| 985 | 983 | /// have a more optimal memset codegen in case it has a repeated byte pattern. |
| 986 | | pub inline fn appendNTimes(self: *Self, allocator: Allocator, value: T, n: usize) Allocator.Error!void { |
| 984 | pub inline fn appendNTimes(self: *Self, gpa: Allocator, value: T, n: usize) Allocator.Error!void { |
| 987 | 985 | const old_len = self.items.len; |
| 988 | | try self.resize(allocator, try addOrOom(old_len, n)); |
| 986 | try self.resize(gpa, try addOrOom(old_len, n)); |
| 989 | 987 | @memset(self.items[old_len..self.items.len], value); |
| 990 | 988 | } |
| 991 | 989 | |
| ... | ... | @@ -1004,15 +1002,15 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 1004 | 1002 | /// Adjust the list length to `new_len`. |
| 1005 | 1003 | /// Additional elements contain the value `undefined`. |
| 1006 | 1004 | /// Invalidates element pointers if additional memory is needed. |
| 1007 | | pub fn resize(self: *Self, allocator: Allocator, new_len: usize) Allocator.Error!void { |
| 1008 | | try self.ensureTotalCapacity(allocator, new_len); |
| 1005 | pub fn resize(self: *Self, gpa: Allocator, new_len: usize) Allocator.Error!void { |
| 1006 | try self.ensureTotalCapacity(gpa, new_len); |
| 1009 | 1007 | self.items.len = new_len; |
| 1010 | 1008 | } |
| 1011 | 1009 | |
| 1012 | 1010 | /// Reduce allocated capacity to `new_len`. |
| 1013 | 1011 | /// May invalidate element pointers. |
| 1014 | 1012 | /// Asserts that the new length is less than or equal to the previous length. |
| 1015 | | pub fn shrinkAndFree(self: *Self, allocator: Allocator, new_len: usize) void { |
| 1013 | pub fn shrinkAndFree(self: *Self, gpa: Allocator, new_len: usize) void { |
| 1016 | 1014 | assert(new_len <= self.items.len); |
| 1017 | 1015 | |
| 1018 | 1016 | if (@sizeOf(T) == 0) { |
| ... | ... | @@ -1021,13 +1019,13 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 1021 | 1019 | } |
| 1022 | 1020 | |
| 1023 | 1021 | const old_memory = self.allocatedSlice(); |
| 1024 | | if (allocator.remap(old_memory, new_len)) |new_items| { |
| 1022 | if (gpa.remap(old_memory, new_len)) |new_items| { |
| 1025 | 1023 | self.capacity = new_items.len; |
| 1026 | 1024 | self.items = new_items; |
| 1027 | 1025 | return; |
| 1028 | 1026 | } |
| 1029 | 1027 | |
| 1030 | | const new_memory = allocator.alignedAlloc(T, alignment, new_len) catch |e| switch (e) { |
| 1028 | const new_memory = gpa.alignedAlloc(T, alignment, new_len) catch |e| switch (e) { |
| 1031 | 1029 | error.OutOfMemory => { |
| 1032 | 1030 | // No problem, capacity is still correct then. |
| 1033 | 1031 | self.items.len = new_len; |
| ... | ... | @@ -1036,7 +1034,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 1036 | 1034 | }; |
| 1037 | 1035 | |
| 1038 | 1036 | @memcpy(new_memory, self.items[0..new_len]); |
| 1039 | | allocator.free(old_memory); |
| 1037 | gpa.free(old_memory); |
| 1040 | 1038 | self.items = new_memory; |
| 1041 | 1039 | self.capacity = new_memory.len; |
| 1042 | 1040 | } |
| ... | ... | @@ -1056,8 +1054,8 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 1056 | 1054 | } |
| 1057 | 1055 | |
| 1058 | 1056 | /// Invalidates all element pointers. |
| 1059 | | pub fn clearAndFree(self: *Self, allocator: Allocator) void { |
| 1060 | | allocator.free(self.allocatedSlice()); |
| 1057 | pub fn clearAndFree(self: *Self, gpa: Allocator) void { |
| 1058 | gpa.free(self.allocatedSlice()); |
| 1061 | 1059 | self.items.len = 0; |
| 1062 | 1060 | self.capacity = 0; |
| 1063 | 1061 | } |
| ... | ... | @@ -1073,7 +1071,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 1073 | 1071 | /// If the current capacity is less than `new_capacity`, this function will |
| 1074 | 1072 | /// modify the array so that it can hold exactly `new_capacity` items. |
| 1075 | 1073 | /// Invalidates element pointers if additional memory is needed. |
| 1076 | | pub fn ensureTotalCapacityPrecise(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void { |
| 1074 | pub fn ensureTotalCapacityPrecise(self: *Self, gpa: Allocator, new_capacity: usize) Allocator.Error!void { |
| 1077 | 1075 | if (@sizeOf(T) == 0) { |
| 1078 | 1076 | self.capacity = math.maxInt(usize); |
| 1079 | 1077 | return; |
| ... | ... | @@ -1087,13 +1085,13 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 1087 | 1085 | // the allocator implementation would pointlessly copy our |
| 1088 | 1086 | // extra capacity. |
| 1089 | 1087 | const old_memory = self.allocatedSlice(); |
| 1090 | | if (allocator.remap(old_memory, new_capacity)) |new_memory| { |
| 1088 | if (gpa.remap(old_memory, new_capacity)) |new_memory| { |
| 1091 | 1089 | self.items.ptr = new_memory.ptr; |
| 1092 | 1090 | self.capacity = new_memory.len; |
| 1093 | 1091 | } else { |
| 1094 | | const new_memory = try allocator.alignedAlloc(T, alignment, new_capacity); |
| 1092 | const new_memory = try gpa.alignedAlloc(T, alignment, new_capacity); |
| 1095 | 1093 | @memcpy(new_memory[0..self.items.len], self.items); |
| 1096 | | allocator.free(old_memory); |
| 1094 | gpa.free(old_memory); |
| 1097 | 1095 | self.items.ptr = new_memory.ptr; |
| 1098 | 1096 | self.capacity = new_memory.len; |
| 1099 | 1097 | } |
| ... | ... | @@ -1103,10 +1101,10 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 1103 | 1101 | /// Invalidates element pointers if additional memory is needed. |
| 1104 | 1102 | pub fn ensureUnusedCapacity( |
| 1105 | 1103 | self: *Self, |
| 1106 | | allocator: Allocator, |
| 1104 | gpa: Allocator, |
| 1107 | 1105 | additional_count: usize, |
| 1108 | 1106 | ) Allocator.Error!void { |
| 1109 | | return self.ensureTotalCapacity(allocator, try addOrOom(self.items.len, additional_count)); |
| 1107 | return self.ensureTotalCapacity(gpa, try addOrOom(self.items.len, additional_count)); |
| 1110 | 1108 | } |
| 1111 | 1109 | |
| 1112 | 1110 | /// Increases the array's length to match the full capacity that is already allocated. |
| ... | ... | @@ -1118,10 +1116,10 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 1118 | 1116 | |
| 1119 | 1117 | /// Increase length by 1, returning pointer to the new item. |
| 1120 | 1118 | /// The returned element pointer becomes invalid when the list is resized. |
| 1121 | | pub fn addOne(self: *Self, allocator: Allocator) Allocator.Error!*T { |
| 1119 | pub fn addOne(self: *Self, gpa: Allocator) Allocator.Error!*T { |
| 1122 | 1120 | // This can never overflow because `self.items` can never occupy the whole address space |
| 1123 | 1121 | const newlen = self.items.len + 1; |
| 1124 | | try self.ensureTotalCapacity(allocator, newlen); |
| 1122 | try self.ensureTotalCapacity(gpa, newlen); |
| 1125 | 1123 | return self.addOneAssumeCapacity(); |
| 1126 | 1124 | } |
| 1127 | 1125 | |
| ... | ... | @@ -1139,9 +1137,9 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 1139 | 1137 | /// Resize the array, adding `n` new elements, which have `undefined` values. |
| 1140 | 1138 | /// The return value is an array pointing to the newly allocated elements. |
| 1141 | 1139 | /// The returned pointer becomes invalid when the list is resized. |
| 1142 | | pub fn addManyAsArray(self: *Self, allocator: Allocator, comptime n: usize) Allocator.Error!*[n]T { |
| 1140 | pub fn addManyAsArray(self: *Self, gpa: Allocator, comptime n: usize) Allocator.Error!*[n]T { |
| 1143 | 1141 | const prev_len = self.items.len; |
| 1144 | | try self.resize(allocator, try addOrOom(self.items.len, n)); |
| 1142 | try self.resize(gpa, try addOrOom(self.items.len, n)); |
| 1145 | 1143 | return self.items[prev_len..][0..n]; |
| 1146 | 1144 | } |
| 1147 | 1145 | |
| ... | ... | @@ -1161,9 +1159,9 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 1161 | 1159 | /// The return value is a slice pointing to the newly allocated elements. |
| 1162 | 1160 | /// The returned pointer becomes invalid when the list is resized. |
| 1163 | 1161 | /// Resizes list if `self.capacity` is not large enough. |
| 1164 | | pub fn addManyAsSlice(self: *Self, allocator: Allocator, n: usize) Allocator.Error![]T { |
| 1162 | pub fn addManyAsSlice(self: *Self, gpa: Allocator, n: usize) Allocator.Error![]T { |
| 1165 | 1163 | const prev_len = self.items.len; |
| 1166 | | try self.resize(allocator, try addOrOom(self.items.len, n)); |
| 1164 | try self.resize(gpa, try addOrOom(self.items.len, n)); |
| 1167 | 1165 | return self.items[prev_len..][0..n]; |
| 1168 | 1166 | } |
| 1169 | 1167 | |