diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-12-29 11:16:28 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-12-29 11:16:28 -0700 |
| commit | e54fd2578195ce7857d921ac22b800d376fb870b (patch) | |
| tree | bcfdeec3c406aeb2a0427d816d0f3d242354fdce /lib/std/array_list.zig | |
| parent | 1590ed9d6aea95e5a21e3455e8edba4cdb374f2c (diff) | |
| parent | 717cf00fe0d68dc1213fb645b184afe1cbf52104 (diff) | |
| download | zig-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.zig | 16 |
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..]; + } }; } |
