authorgravatar for goon.pri.low@gmail.comKendall Condon <goon.pri.low@gmail.com> 2024-07-14 00:56:29+00:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-07-14 00:56:29+00:00
logee6a52b40f9836beb0d35820d1987f3c7e522f45
tree2b2997877b7d2d4b8c6038271edbfeb17e37f787
parent944c6d40ce520f345450a15006498dd760fc3d3a
signaturebadge-check Signed by PGP key B5690EEEBB952194

std.ArrayList.unusedCapacitySlice: Return unaligned slice (#20490)


1 files changed, 9 insertions(+), 2 deletions(-)

lib/std/array_list.zig+9-2
......@@ -566,7 +566,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
566566 /// This can be useful for writing directly into an ArrayList.
567567 /// Note that such an operation must be followed up with a direct
568568 /// modification of `self.items.len`.
569 pub fn unusedCapacitySlice(self: Self) Slice {
569 pub fn unusedCapacitySlice(self: Self) []T {
570570 return self.allocatedSlice()[self.items.len..];
571571 }
572572
......@@ -1193,7 +1193,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
11931193 /// This can be useful for writing directly into an ArrayList.
11941194 /// Note that such an operation must be followed up with a direct
11951195 /// modification of `self.items.len`.
1196 pub fn unusedCapacitySlice(self: Self) Slice {
1196 pub fn unusedCapacitySlice(self: Self) []T {
11971197 return self.allocatedSlice()[self.items.len..];
11981198 }
11991199
......@@ -2242,3 +2242,10 @@ test "return OutOfMemory when capacity would exceed maximum usize integer value"
22422242 try testing.expectError(error.OutOfMemory, list.ensureUnusedCapacity(2));
22432243 }
22442244}
2245
2246test "ArrayListAligned with non-native alignment compiles unusedCapabitySlice" {
2247 var list = ArrayListAligned(u8, 4).init(testing.allocator);
2248 defer list.deinit();
2249 try list.appendNTimes(1, 4);
2250 _ = list.unusedCapacitySlice();
2251}