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).
This commit is contained in:
mlugg 2025-01-21 22:04:16 +00:00
parent 28a259d4a3
commit f244c8891a
No known key found for this signature in database
GPG Key ID: 3F5B7DCCBF4AF02E

View File

@ -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