authorgravatar for lucascarvalhosantos91@gmail.comLucas Santos <lucascarvalhosantos91@gmail.com> 2024-05-09 21:39:11-03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2024-05-10 22:51:52+03:00
logf71f27bcb0ceb851a7c95f3970d644623b8d67ba
tree7811b7a0c8a678a3d216f86354ec84c792674b5d
parentfe1b3976064e2d5b08590bf78aa4f4220c757da3

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 {...@@ -19,18 +19,22 @@ fn alloc(_: *anyopaque, n: usize, log2_align: u8, ra: usize) ?[*]u8 {
19 _ = log2_align;19 _ = log2_align;
20 assert(n > 0);20 assert(n > 0);
21 if (n > maxInt(usize) - (mem.page_size - 1)) return null;21 if (n > maxInt(usize) - (mem.page_size - 1)) return null;
22 const aligned_len = mem.alignForward(usize, n, mem.page_size);
2322
24 if (native_os == .windows) {23 if (native_os == .windows) {
25 const addr = windows.VirtualAlloc(24 const addr = windows.VirtualAlloc(
26 null,25 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
28 windows.MEM_COMMIT | windows.MEM_RESERVE,31 windows.MEM_COMMIT | windows.MEM_RESERVE,
29 windows.PAGE_READWRITE,32 windows.PAGE_READWRITE,
30 ) catch return null;33 ) catch return null;
31 return @ptrCast(addr);34 return @ptrCast(addr);
32 }35 }
3336
37 const aligned_len = mem.alignForward(usize, n, mem.page_size);
34 const hint = @atomicLoad(@TypeOf(std.heap.next_mmap_addr_hint), &std.heap.next_mmap_addr_hint, .unordered);38 const hint = @atomicLoad(@TypeOf(std.heap.next_mmap_addr_hint), &std.heap.next_mmap_addr_hint, .unordered);
35 const slice = posix.mmap(39 const slice = posix.mmap(
36 hint,40 hint,