std.mem.Allocator: allow shrink to fail

closes #13535
This commit is contained in:
Andrew Kelley
2022-11-27 01:07:35 -07:00
parent deda6b5146
commit ceb0a632cf
57 changed files with 950 additions and 1279 deletions

View File

@@ -288,11 +288,10 @@ pub fn MultiArrayList(comptime S: type) type {
assert(new_len <= self.capacity);
assert(new_len <= self.len);
const other_bytes = gpa.allocAdvanced(
const other_bytes = gpa.alignedAlloc(
u8,
@alignOf(S),
capacityInBytes(new_len),
.exact,
) catch {
const self_slice = self.slice();
inline for (fields) |field_info, i| {
@@ -360,11 +359,10 @@ pub fn MultiArrayList(comptime S: type) type {
/// `new_capacity` must be greater or equal to `len`.
pub fn setCapacity(self: *Self, gpa: Allocator, new_capacity: usize) !void {
assert(new_capacity >= self.len);
const new_bytes = try gpa.allocAdvanced(
const new_bytes = try gpa.alignedAlloc(
u8,
@alignOf(S),
capacityInBytes(new_capacity),
.exact,
);
if (self.len == 0) {
gpa.free(self.allocatedBytes());