authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-01-21 22:04:16+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-01-22 02:00:47+00:00
logf244c8891a6956fb9560c26e516278052b5acef5
tree848104899a3216cd5e749c991e7ec9bb5e323b6c
parent28a259d4a34e544090a76863802e600a4e01fcc2
signaturelock-open Commit is signed but in an unrecognized format.

std.mem.Allocator: remove redundant check

This check doesn't make sense with the modern Allocator API; it's left over from when realloc could change alignment. It's statically known (but not comptime-known) to be true always. This check was one of the things blocking Allocator from being used at comptime (related: #1291).

1 files changed, 3 insertions(+), 5 deletions(-)

lib/std/mem/Allocator.zig+3-5
...@@ -282,11 +282,9 @@ pub fn reallocAdvanced(...@@ -282,11 +282,9 @@ pub fn reallocAdvanced(
282 const old_byte_slice = mem.sliceAsBytes(old_mem);282 const old_byte_slice = mem.sliceAsBytes(old_mem);
283 const byte_count = math.mul(usize, @sizeOf(T), new_n) catch return Error.OutOfMemory;283 const byte_count = math.mul(usize, @sizeOf(T), new_n) catch return Error.OutOfMemory;
284 // Note: can't set shrunk memory to undefined as memory shouldn't be modified on realloc failure284 // Note: can't set shrunk memory to undefined as memory shouldn't be modified on realloc failure
285 if (mem.isAligned(@intFromPtr(old_byte_slice.ptr), Slice.alignment)) {285 if (self.rawResize(old_byte_slice, log2a(Slice.alignment), byte_count, return_address)) {
286 if (self.rawResize(old_byte_slice, log2a(Slice.alignment), byte_count, return_address)) {286 const new_bytes: []align(Slice.alignment) u8 = @alignCast(old_byte_slice.ptr[0..byte_count]);
287 const new_bytes: []align(Slice.alignment) u8 = @alignCast(old_byte_slice.ptr[0..byte_count]);287 return mem.bytesAsSlice(T, new_bytes);
288 return mem.bytesAsSlice(T, new_bytes);
289 }
290 }288 }
291289
292 const new_mem = self.rawAlloc(byte_count, log2a(Slice.alignment), return_address) orelse290 const new_mem = self.rawAlloc(byte_count, log2a(Slice.alignment), return_address) orelse