From c98e58c4abad8cedfdefe18e700a28ae2af594ad Mon Sep 17 00:00:00 2001 From: Archbirdplus Date: Thu, 8 Aug 2024 13:57:44 -0700 Subject: [PATCH] page size: fix fmt --- lib/std/c.zig | 2 +- lib/std/heap.zig | 22 ++++++++++++++-------- lib/std/heap/general_purpose_allocator.zig | 8 ++++++-- lib/std/posix/test.zig | 2 +- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/lib/std/c.zig b/lib/std/c.zig index e32d7e5234e3..fc171f61f32c 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -2239,7 +2239,7 @@ pub const _SC = switch (native_os) { pub const PAGESIZE = 11; pub const NPROCESSORS_ONLN = 15; }, -} +}; pub const SEEK = switch (native_os) { .linux => linux.SEEK, diff --git a/lib/std/heap.zig b/lib/std/heap.zig index c0f43e245082..1e077020adf0 100644 --- a/lib/std/heap.zig +++ b/lib/std/heap.zig @@ -12,12 +12,14 @@ const page_size_darwin: ?comptime_int = if (builtin.os.tag.isDarwin()) switch (builtin.cpu.arch) { .x86, .x86_64 => 4 << 10, .thumb, .thumbeb, .arm, .armeb, .aarch64, .aarch64_be, .aarch64_32 => 16 << 10, - else => null + else => null, } -else null; +else + null; // -- -const page_size_windows: ?comptime_int = if (builtin.os.tag == .windows and builtin.os.version_range.windows.min.isAtLeast(.xp)) blk: { +const page_size_windows: ?comptime_int = if (builtin.os.tag == .windows and builtin.os.version_range.windows.min.isAtLeast(.xp)) +blk: { break :blk switch (builtin.cpu.arch) { .x86, .x86_64 => 4 << 10, // SuperH => 4 << 10, @@ -26,7 +28,7 @@ const page_size_windows: ?comptime_int = if (builtin.os.tag == .windows and buil // DEC Alpha => 8 << 10, // Itanium => 8 << 10, .thumb, .thumbeb, .arm, .armeb, .aarch64, .aarch64_be, .aarch64_32 => 4 << 10, - else => null + else => null, }; } else null; @@ -88,7 +90,9 @@ var runtimePageSize = std.atomic.Value(usize).init(0); /// Runtime detected page size. pub inline fn pageSize() usize { - if (@inComptime()) { @compileError("pageSize() must NOT be used in comptime. Use page_size variants instead."); } + if (@inComptime()) { + @compileError("pageSize() must NOT be used in comptime. Use page_size variants instead."); + } if (page_size == page_size_cap) { assert(queryPageSize() == page_size); return page_size; @@ -100,7 +104,7 @@ pub inline fn pageSize() usize { // Runtime queried page size. fn queryPageSize() usize { var size = runtimePageSize.load(.unordered); - if(size > 0) return size; + if (size > 0) return size; defer { std.debug.assert(size > 0); std.debug.assert(size >= page_size); @@ -132,7 +136,7 @@ fn queryPageSize() usize { var vm_page_size: std.c.vm_size_t = undefined; switch (std.c._host_page_size(std.c.mach_host_self(), &vm_page_size)) { 0 => size = vm_page_size, - else => {} + else => {}, } }, .windows => { @@ -140,7 +144,9 @@ fn queryPageSize() usize { std.os.windows.kernel32.GetSystemInfo(&info); size = info.dwPageSize; }, - else => if (@hasDecl(std.c, "_SC") and @hasDecl(std.c._SC, "PAGE_SIZE")) { size = std.c.sysconf(std.c._SC.PAGE_SIZE); } else {}, + else => if (@hasDecl(std.c, "_SC") and @hasDecl(std.c._SC, "PAGE_SIZE")) { + size = std.c.sysconf(std.c._SC.PAGE_SIZE); + } else {}, } return size; } diff --git a/lib/std/heap/general_purpose_allocator.zig b/lib/std/heap/general_purpose_allocator.zig index 05e443105037..eaab2939919e 100644 --- a/lib/std/heap/general_purpose_allocator.zig +++ b/lib/std/heap/general_purpose_allocator.zig @@ -203,7 +203,9 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { var small_bucket_count_cache = std.atomic.Value(usize).init(0); fn small_bucket_count() usize { const cached = small_bucket_count_cache.load(.monotonic); - if(cached != 0) { return cached; } + if (cached != 0) { + return cached; + } const val = math.log2(pageSize()); small_bucket_count_cache.store(val, .monotonic); return val; @@ -211,7 +213,9 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { var largest_bucket_object_size_cache = std.atomic.Value(usize).init(0); fn largest_bucket_object_size() usize { const cached = largest_bucket_object_size_cache.load(.monotonic); - if(cached != 0) { return cached; } + if (cached != 0) { + return cached; + } const val = @as(usize, 1) << @truncate(small_bucket_count() - 1); largest_bucket_object_size_cache.store(val, .monotonic); return val; diff --git a/lib/std/posix/test.zig b/lib/std/posix/test.zig index 6572fc89156a..be972c6572da 100644 --- a/lib/std/posix/test.zig +++ b/lib/std/posix/test.zig @@ -1323,5 +1323,5 @@ const CommonOpenFlags = packed struct { test "pageSize() smoke test" { const size = std.heap.pageSize(); // Check that pageSize is a power of 2. - std.debug.assert(size == (1 << @ctz(size)); + std.debug.assert(size == (1 << @ctz(size))); }