diff options
| author | gooncreeper <149842806+gooncreeper@users.noreply.github.com> | 2024-07-14 00:56:29 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-14 00:56:29 +0000 |
| commit | ee6a52b40f9836beb0d35820d1987f3c7e522f45 (patch) | |
| tree | 2b2997877b7d2d4b8c6038271edbfeb17e37f787 /lib/std/array_list.zig | |
| parent | 944c6d40ce520f345450a15006498dd760fc3d3a (diff) | |
| download | zig-ee6a52b40f9836beb0d35820d1987f3c7e522f45.tar.gz zig-ee6a52b40f9836beb0d35820d1987f3c7e522f45.zip | |
std.ArrayList.unusedCapacitySlice: Return unaligned slice (#20490)
Diffstat (limited to 'lib/std/array_list.zig')
| -rw-r--r-- | lib/std/array_list.zig | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig index 29902db34f..7b93668c5c 100644 --- a/lib/std/array_list.zig +++ b/lib/std/array_list.zig @@ -566,7 +566,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { /// 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 { + pub fn unusedCapacitySlice(self: Self) []T { return self.allocatedSlice()[self.items.len..]; } @@ -1193,7 +1193,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ /// 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 { + pub fn unusedCapacitySlice(self: Self) []T { return self.allocatedSlice()[self.items.len..]; } @@ -2242,3 +2242,10 @@ test "return OutOfMemory when capacity would exceed maximum usize integer value" try testing.expectError(error.OutOfMemory, list.ensureUnusedCapacity(2)); } } + +test "ArrayListAligned with non-native alignment compiles unusedCapabitySlice" { + var list = ArrayListAligned(u8, 4).init(testing.allocator); + defer list.deinit(); + try list.appendNTimes(1, 4); + _ = list.unusedCapacitySlice(); +} |
