aboutsummaryrefslogtreecommitdiff
path: root/lib/std/array_list.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-08-29 20:19:23 -0700
committerAndrew Kelley <andrew@ziglang.org>2025-08-30 00:48:50 -0700
commit9a0970a12bdcae105b6f3f65c0a72d95a209bd35 (patch)
treeab0de8f2447b5e52c2bb5c92a976a52fb4b613ee /lib/std/array_list.zig
parent79f267f6b9e7f80a6fed3b1019f9de942841c3be (diff)
downloadzig-9a0970a12bdcae105b6f3f65c0a72d95a209bd35.tar.gz
zig-9a0970a12bdcae105b6f3f65c0a72d95a209bd35.zip
rework std.Io.Writer.Allocating to support runtime-known alignment
Also, breaking API changes to: * std.fs.Dir.readFileAlloc * std.fs.Dir.readFileAllocOptions
Diffstat (limited to 'lib/std/array_list.zig')
-rw-r--r--lib/std/array_list.zig5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig
index cab1c6f5a3..a218e47276 100644
--- a/lib/std/array_list.zig
+++ b/lib/std/array_list.zig
@@ -664,9 +664,10 @@ pub fn Aligned(comptime T: type, comptime alignment: ?mem.Alignment) type {
/// The caller owns the returned memory. ArrayList becomes empty.
pub fn toOwnedSliceSentinel(self: *Self, gpa: 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.ensureTotalCapacityPrecise(gpa, self.items.len + 1);
self.appendAssumeCapacity(sentinel);
+ errdefer self.items.len -= 1;
const result = try self.toOwnedSlice(gpa);
return result[0 .. result.len - 1 :sentinel];
}
@@ -1361,7 +1362,7 @@ pub fn Aligned(comptime T: type, comptime alignment: ?mem.Alignment) type {
/// Called when memory growth is necessary. Returns a capacity larger than
/// minimum that grows super-linearly.
- fn growCapacity(current: usize, minimum: usize) usize {
+ pub fn growCapacity(current: usize, minimum: usize) usize {
var new = current;
while (true) {
new +|= new / 2 + init_capacity;