authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-12-03 17:09:51-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-12-03 17:09:51-08:00
log933f7baa83d3a13373ff36e5028130ce428effa8
treedf7906df0aea726d4eeabbf973afa9e2c4376058
parentb3cd5b23a228d4f2b0253d90efa9bc326338b66c

std.ArrayList: rename "precise" to "exact"

This word is shorter and has a more accurate definition.

1 files changed, 10 insertions(+), 10 deletions(-)

lib/std/array_list.zig+10-10
...@@ -63,7 +63,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -63,7 +63,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
63 /// Deinitialize with `deinit` or use `toOwnedSlice`.63 /// Deinitialize with `deinit` or use `toOwnedSlice`.
64 pub fn initCapacity(allocator: Allocator, num: usize) Allocator.Error!Self {64 pub fn initCapacity(allocator: Allocator, num: usize) Allocator.Error!Self {
65 var self = Self.init(allocator);65 var self = Self.init(allocator);
66 try self.reserveTotalPrecise(num);66 try self.reserveTotalExact(num);
67 return self;67 return self;
68 }68 }
6969
...@@ -127,7 +127,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -127,7 +127,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
127 /// The caller owns the returned memory. Empties this ArrayList.127 /// The caller owns the returned memory. Empties this ArrayList.
128 pub fn toOwnedSliceSentinel(self: *Self, comptime sentinel: T) Allocator.Error!SentinelSlice(sentinel) {128 pub fn toOwnedSliceSentinel(self: *Self, comptime sentinel: T) Allocator.Error!SentinelSlice(sentinel) {
129 // This addition can never overflow because `self.items` can never occupy the whole address space129 // This addition can never overflow because `self.items` can never occupy the whole address space
130 try self.reserveTotalPrecise(self.items.len + 1);130 try self.reserveTotalExact(self.items.len + 1);
131 self.appendReserved(sentinel);131 self.appendReserved(sentinel);
132 const result = try self.toOwnedSlice();132 const result = try self.toOwnedSlice();
133 return result[0 .. result.len - 1 :sentinel];133 return result[0 .. result.len - 1 :sentinel];
...@@ -473,16 +473,16 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -473,16 +473,16 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
473 if (self.capacity >= new_capacity) return;473 if (self.capacity >= new_capacity) return;
474474
475 const better_capacity = growCapacity(self.capacity, new_capacity);475 const better_capacity = growCapacity(self.capacity, new_capacity);
476 return self.reserveTotalPrecise(better_capacity);476 return self.reserveTotalExact(better_capacity);
477 }477 }
478478
479 /// Deprecated. To be removed after 0.14.0 is tagged.479 /// Deprecated. To be removed after 0.14.0 is tagged.
480 pub const ensureTotalCapacityPrecise = reserveTotalPrecise;480 pub const ensureTotalCapacityPrecise = reserveTotalExact;
481481
482 /// If the current capacity is less than `new_capacity`, this function will482 /// If the current capacity is less than `new_capacity`, this function will
483 /// modify the array so that it can hold exactly `new_capacity` items.483 /// modify the array so that it can hold exactly `new_capacity` items.
484 /// Invalidates element pointers if additional memory is needed.484 /// Invalidates element pointers if additional memory is needed.
485 pub fn reserveTotalPrecise(self: *Self, new_capacity: usize) Allocator.Error!void {485 pub fn reserveTotalExact(self: *Self, new_capacity: usize) Allocator.Error!void {
486 if (@sizeOf(T) == 0) {486 if (@sizeOf(T) == 0) {
487 self.capacity = math.maxInt(usize);487 self.capacity = math.maxInt(usize);
488 return;488 return;
...@@ -696,7 +696,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -696,7 +696,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
696 /// Deinitialize with `deinit` or use `toOwnedSlice`.696 /// Deinitialize with `deinit` or use `toOwnedSlice`.
697 pub fn initCapacity(allocator: Allocator, num: usize) Allocator.Error!Self {697 pub fn initCapacity(allocator: Allocator, num: usize) Allocator.Error!Self {
698 var self = Self{};698 var self = Self{};
699 try self.reserveTotalPrecise(allocator, num);699 try self.reserveTotalExact(allocator, num);
700 return self;700 return self;
701 }701 }
702702
...@@ -763,7 +763,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -763,7 +763,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
763 /// The caller owns the returned memory. ArrayList becomes empty.763 /// The caller owns the returned memory. ArrayList becomes empty.
764 pub fn toOwnedSliceSentinel(self: *Self, allocator: Allocator, comptime sentinel: T) Allocator.Error!SentinelSlice(sentinel) {764 pub fn toOwnedSliceSentinel(self: *Self, allocator: Allocator, comptime sentinel: T) Allocator.Error!SentinelSlice(sentinel) {
765 // This addition can never overflow because `self.items` can never occupy the whole address space765 // This addition can never overflow because `self.items` can never occupy the whole address space
766 try self.reserveTotalPrecise(allocator, self.items.len + 1);766 try self.reserveTotalExact(allocator, self.items.len + 1);
767 self.appendReserved(sentinel);767 self.appendReserved(sentinel);
768 const result = try self.toOwnedSlice(allocator);768 const result = try self.toOwnedSlice(allocator);
769 return result[0 .. result.len - 1 :sentinel];769 return result[0 .. result.len - 1 :sentinel];
...@@ -1144,16 +1144,16 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -1144,16 +1144,16 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
1144 if (self.capacity >= new_capacity) return;1144 if (self.capacity >= new_capacity) return;
11451145
1146 const better_capacity = growCapacity(self.capacity, new_capacity);1146 const better_capacity = growCapacity(self.capacity, new_capacity);
1147 return self.reserveTotalPrecise(allocator, better_capacity);1147 return self.reserveTotalExact(allocator, better_capacity);
1148 }1148 }
11491149
1150 /// Deprecated. To be removed after 0.14.0 is tagged.1150 /// Deprecated. To be removed after 0.14.0 is tagged.
1151 pub const ensureTotalCapacityPrecise = reserveTotalPrecise;1151 pub const ensureTotalCapacityPrecise = reserveTotalExact;
11521152
1153 /// If the current capacity is less than `new_capacity`, this function will1153 /// If the current capacity is less than `new_capacity`, this function will
1154 /// modify the array so that it can hold exactly `new_capacity` items.1154 /// modify the array so that it can hold exactly `new_capacity` items.
1155 /// Invalidates element pointers if additional memory is needed.1155 /// Invalidates element pointers if additional memory is needed.
1156 pub fn reserveTotalPrecise(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void {1156 pub fn reserveTotalExact(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void {
1157 if (@sizeOf(T) == 0) {1157 if (@sizeOf(T) == 0) {
1158 self.capacity = math.maxInt(usize);1158 self.capacity = math.maxInt(usize);
1159 return;1159 return;