authorgravatar for lucascarvalhosantos91@gmail.comLucas Santos <lucascarvalhosantos91@gmail.com> 2024-05-09 21:39:11-03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-05-22 07:03:25-07:00
loge57c9c0931cba3cdec6fba562aeb5c1910d8f2c4
treef1f099f8195f0943c250a899922bc3abf6a7492e
parentd37182383d9e16a123bf89ffdaaa119bbac1d35f

Avoid unnecessary operation in PageAllocator.

There's no need to call `alignForward` before `VirtualAlloc`. From [MSDN](https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-virtualalloc): ``` If the lpAddress parameter is NULL, this value is rounded up to the next page boundary ```

1 files changed, 6 insertions(+), 2 deletions(-)

lib/std/heap/PageAllocator.zig+6-2
......@@ -19,18 +19,22 @@ fn alloc(_: *anyopaque, n: usize, log2_align: u8, ra: usize) ?[*]u8 {
1919 _ = log2_align;
2020 assert(n > 0);
2121 if (n > maxInt(usize) - (mem.page_size - 1)) return null;
22 const aligned_len = mem.alignForward(usize, n, mem.page_size);
2322
2423 if (native_os == .windows) {
2524 const addr = windows.VirtualAlloc(
2625 null,
27 aligned_len,
26
27 // VirtualAlloc will round the length to a multiple of page size.
28 // VirtualAlloc docs: If the lpAddress parameter is NULL, this value is rounded up to the next page boundary
29 n,
30
2831 windows.MEM_COMMIT | windows.MEM_RESERVE,
2932 windows.PAGE_READWRITE,
3033 ) catch return null;
3134 return @ptrCast(addr);
3235 }
3336
37 const aligned_len = mem.alignForward(usize, n, mem.page_size);
3438 const hint = @atomicLoad(@TypeOf(std.heap.next_mmap_addr_hint), &std.heap.next_mmap_addr_hint, .unordered);
3539 const slice = posix.mmap(
3640 hint,