aboutsummaryrefslogtreecommitdiff
path: root/lib/std/array_list.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-12-29 11:16:28 -0700
committerAndrew Kelley <andrew@ziglang.org>2020-12-29 11:16:28 -0700
commite54fd2578195ce7857d921ac22b800d376fb870b (patch)
treebcfdeec3c406aeb2a0427d816d0f3d242354fdce /lib/std/array_list.zig
parent1590ed9d6aea95e5a21e3455e8edba4cdb374f2c (diff)
parent717cf00fe0d68dc1213fb645b184afe1cbf52104 (diff)
downloadzig-e54fd2578195ce7857d921ac22b800d376fb870b.tar.gz
zig-e54fd2578195ce7857d921ac22b800d376fb870b.zip
Merge branch 'LemonBoy-cprocess'
This is a partial merge of #6750. I took the Posix code paths and dropped the Windows code paths, and then did the improvements noted in the comments. The Windows implementation is still TODO.
Diffstat (limited to 'lib/std/array_list.zig')
-rw-r--r--lib/std/array_list.zig16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig
index 4a8e0059e9..292e421bb1 100644
--- a/lib/std/array_list.zig
+++ b/lib/std/array_list.zig
@@ -337,11 +337,21 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
return self.pop();
}
- // For a nicer API, `items.len` is the length, not the capacity.
- // This requires "unsafe" slicing.
- fn allocatedSlice(self: Self) Slice {
+ /// Returns a slice of all the items plus the extra capacity, whose memory
+ /// contents are undefined.
+ pub fn allocatedSlice(self: Self) Slice {
+ // For a nicer API, `items.len` is the length, not the capacity.
+ // This requires "unsafe" slicing.
return self.items.ptr[0..self.capacity];
}
+
+ /// Returns a slice of only the extra capacity after items.
+ /// This can be useful for writing directly into an `ArrayList`.
+ /// Note that such an operation must be followed up with a direct
+ /// modification of `self.items.len`.
+ pub fn unusedCapacitySlice(self: Self) Slice {
+ return self.allocatedSlice()[self.items.len..];
+ }
};
}