mirror of
https://github.com/ziglang/zig.git
synced 2026-02-16 14:28:57 +00:00
std.ArrayList.unusedCapacitySlice: Return unaligned slice (#20490)
This commit is contained in:
parent
944c6d40ce
commit
ee6a52b40f
@ -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();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user