mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
std.ArrayList: rename "precise" to "exact"
This word is shorter and has a more accurate definition.
This commit is contained in:
parent
b3cd5b23a2
commit
933f7baa83
1 changed files with 10 additions and 10 deletions
|
|
@ -63,7 +63,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
|
||||||
/// Deinitialize with `deinit` or use `toOwnedSlice`.
|
/// Deinitialize with `deinit` or use `toOwnedSlice`.
|
||||||
pub fn initCapacity(allocator: Allocator, num: usize) Allocator.Error!Self {
|
pub fn initCapacity(allocator: Allocator, num: usize) Allocator.Error!Self {
|
||||||
var self = Self.init(allocator);
|
var self = Self.init(allocator);
|
||||||
try self.reserveTotalPrecise(num);
|
try self.reserveTotalExact(num);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,7 +127,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
|
||||||
/// The caller owns the returned memory. Empties this ArrayList.
|
/// The caller owns the returned memory. Empties this ArrayList.
|
||||||
pub fn toOwnedSliceSentinel(self: *Self, comptime sentinel: T) Allocator.Error!SentinelSlice(sentinel) {
|
pub fn toOwnedSliceSentinel(self: *Self, comptime sentinel: T) Allocator.Error!SentinelSlice(sentinel) {
|
||||||
// This addition can never overflow because `self.items` can never occupy the whole address space
|
// This addition can never overflow because `self.items` can never occupy the whole address space
|
||||||
try self.reserveTotalPrecise(self.items.len + 1);
|
try self.reserveTotalExact(self.items.len + 1);
|
||||||
self.appendReserved(sentinel);
|
self.appendReserved(sentinel);
|
||||||
const result = try self.toOwnedSlice();
|
const result = try self.toOwnedSlice();
|
||||||
return result[0 .. result.len - 1 :sentinel];
|
return result[0 .. result.len - 1 :sentinel];
|
||||||
|
|
@ -473,16 +473,16 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
|
||||||
if (self.capacity >= new_capacity) return;
|
if (self.capacity >= new_capacity) return;
|
||||||
|
|
||||||
const better_capacity = growCapacity(self.capacity, new_capacity);
|
const better_capacity = growCapacity(self.capacity, new_capacity);
|
||||||
return self.reserveTotalPrecise(better_capacity);
|
return self.reserveTotalExact(better_capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deprecated. To be removed after 0.14.0 is tagged.
|
/// Deprecated. To be removed after 0.14.0 is tagged.
|
||||||
pub const ensureTotalCapacityPrecise = reserveTotalPrecise;
|
pub const ensureTotalCapacityPrecise = reserveTotalExact;
|
||||||
|
|
||||||
/// If the current capacity is less than `new_capacity`, this function will
|
/// If the current capacity is less than `new_capacity`, this function will
|
||||||
/// modify the array so that it can hold exactly `new_capacity` items.
|
/// modify the array so that it can hold exactly `new_capacity` items.
|
||||||
/// Invalidates element pointers if additional memory is needed.
|
/// Invalidates element pointers if additional memory is needed.
|
||||||
pub fn reserveTotalPrecise(self: *Self, new_capacity: usize) Allocator.Error!void {
|
pub fn reserveTotalExact(self: *Self, new_capacity: usize) Allocator.Error!void {
|
||||||
if (@sizeOf(T) == 0) {
|
if (@sizeOf(T) == 0) {
|
||||||
self.capacity = math.maxInt(usize);
|
self.capacity = math.maxInt(usize);
|
||||||
return;
|
return;
|
||||||
|
|
@ -696,7 +696,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
|
||||||
/// Deinitialize with `deinit` or use `toOwnedSlice`.
|
/// Deinitialize with `deinit` or use `toOwnedSlice`.
|
||||||
pub fn initCapacity(allocator: Allocator, num: usize) Allocator.Error!Self {
|
pub fn initCapacity(allocator: Allocator, num: usize) Allocator.Error!Self {
|
||||||
var self = Self{};
|
var self = Self{};
|
||||||
try self.reserveTotalPrecise(allocator, num);
|
try self.reserveTotalExact(allocator, num);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -763,7 +763,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
|
||||||
/// The caller owns the returned memory. ArrayList becomes empty.
|
/// The caller owns the returned memory. ArrayList becomes empty.
|
||||||
pub fn toOwnedSliceSentinel(self: *Self, allocator: Allocator, comptime sentinel: T) Allocator.Error!SentinelSlice(sentinel) {
|
pub fn toOwnedSliceSentinel(self: *Self, allocator: Allocator, comptime sentinel: T) Allocator.Error!SentinelSlice(sentinel) {
|
||||||
// This addition can never overflow because `self.items` can never occupy the whole address space
|
// This addition can never overflow because `self.items` can never occupy the whole address space
|
||||||
try self.reserveTotalPrecise(allocator, self.items.len + 1);
|
try self.reserveTotalExact(allocator, self.items.len + 1);
|
||||||
self.appendReserved(sentinel);
|
self.appendReserved(sentinel);
|
||||||
const result = try self.toOwnedSlice(allocator);
|
const result = try self.toOwnedSlice(allocator);
|
||||||
return result[0 .. result.len - 1 :sentinel];
|
return result[0 .. result.len - 1 :sentinel];
|
||||||
|
|
@ -1144,16 +1144,16 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
|
||||||
if (self.capacity >= new_capacity) return;
|
if (self.capacity >= new_capacity) return;
|
||||||
|
|
||||||
const better_capacity = growCapacity(self.capacity, new_capacity);
|
const better_capacity = growCapacity(self.capacity, new_capacity);
|
||||||
return self.reserveTotalPrecise(allocator, better_capacity);
|
return self.reserveTotalExact(allocator, better_capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deprecated. To be removed after 0.14.0 is tagged.
|
/// Deprecated. To be removed after 0.14.0 is tagged.
|
||||||
pub const ensureTotalCapacityPrecise = reserveTotalPrecise;
|
pub const ensureTotalCapacityPrecise = reserveTotalExact;
|
||||||
|
|
||||||
/// If the current capacity is less than `new_capacity`, this function will
|
/// If the current capacity is less than `new_capacity`, this function will
|
||||||
/// modify the array so that it can hold exactly `new_capacity` items.
|
/// modify the array so that it can hold exactly `new_capacity` items.
|
||||||
/// Invalidates element pointers if additional memory is needed.
|
/// Invalidates element pointers if additional memory is needed.
|
||||||
pub fn reserveTotalPrecise(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void {
|
pub fn reserveTotalExact(self: *Self, allocator: Allocator, new_capacity: usize) Allocator.Error!void {
|
||||||
if (@sizeOf(T) == 0) {
|
if (@sizeOf(T) == 0) {
|
||||||
self.capacity = math.maxInt(usize);
|
self.capacity = math.maxInt(usize);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue