From f244c8891a6956fb9560c26e516278052b5acef5 Mon Sep 17 00:00:00 2001 From: mlugg Date: Tue, 21 Jan 2025 22:04:16 +0000 Subject: [PATCH] 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). --- lib/std/mem/Allocator.zig | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/std/mem/Allocator.zig b/lib/std/mem/Allocator.zig index c6b0369127..7cf201d4b1 100644 --- a/lib/std/mem/Allocator.zig +++ b/lib/std/mem/Allocator.zig @@ -282,11 +282,9 @@ pub fn reallocAdvanced( const old_byte_slice = mem.sliceAsBytes(old_mem); const byte_count = math.mul(usize, @sizeOf(T), new_n) catch return Error.OutOfMemory; // Note: can't set shrunk memory to undefined as memory shouldn't be modified on realloc failure - if (mem.isAligned(@intFromPtr(old_byte_slice.ptr), Slice.alignment)) { - if (self.rawResize(old_byte_slice, log2a(Slice.alignment), byte_count, return_address)) { - const new_bytes: []align(Slice.alignment) u8 = @alignCast(old_byte_slice.ptr[0..byte_count]); - return mem.bytesAsSlice(T, new_bytes); - } + if (self.rawResize(old_byte_slice, log2a(Slice.alignment), byte_count, return_address)) { + const new_bytes: []align(Slice.alignment) u8 = @alignCast(old_byte_slice.ptr[0..byte_count]); + return mem.bytesAsSlice(T, new_bytes); } const new_mem = self.rawAlloc(byte_count, log2a(Slice.alignment), return_address) orelse