authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-02-23 21:27:51-08:00
committergravatar for david@vortan.devDavid Rubin <david@vortan.dev> 2025-02-25 11:22:33-08:00
logfaf256e429914a816dd5ab1555671b7ee69ecc4e
tree0d18c16ef226ba40119455d0e9ed4a8ea2c82512
parente18c7f9cca42731792cb9700744380197812747e

std.mem.indexOfSentinel: don't ask the OS the page size

simply use page_size_min instead. better yet, this logic would avoid depending on page size entirely...

1 files changed, 3 insertions(+), 3 deletions(-)

lib/std/mem.zig+3-3
...@@ -1098,12 +1098,12 @@ pub fn indexOfSentinel(comptime T: type, comptime sentinel: T, p: [*:sentinel]co...@@ -1098,12 +1098,12 @@ pub fn indexOfSentinel(comptime T: type, comptime sentinel: T, p: [*:sentinel]co
1098 // as we don't read into a new page. This should be the case for most architectures1098 // as we don't read into a new page. This should be the case for most architectures
1099 // which use paged memory, however should be confirmed before adding a new arch below.1099 // which use paged memory, however should be confirmed before adding a new arch below.
1100 .aarch64, .x86, .x86_64 => if (std.simd.suggestVectorLength(T)) |block_len| {1100 .aarch64, .x86, .x86_64 => if (std.simd.suggestVectorLength(T)) |block_len| {
1101 const page_size = std.heap.pageSize();1101 const page_size = std.heap.page_size_min;
1102 const block_size = @sizeOf(T) * block_len;1102 const block_size = @sizeOf(T) * block_len;
1103 const Block = @Vector(block_len, T);1103 const Block = @Vector(block_len, T);
1104 const mask: Block = @splat(sentinel);1104 const mask: Block = @splat(sentinel);
11051105
1106 comptime assert(std.heap.page_size_max % @sizeOf(Block) == 0);1106 comptime assert(std.heap.page_size_min % @sizeOf(Block) == 0);
1107 assert(page_size % @sizeOf(Block) == 0);1107 assert(page_size % @sizeOf(Block) == 0);
11081108
1109 // First block may be unaligned1109 // First block may be unaligned
...@@ -1153,7 +1153,7 @@ pub fn indexOfSentinel(comptime T: type, comptime sentinel: T, p: [*:sentinel]co...@@ -1153,7 +1153,7 @@ pub fn indexOfSentinel(comptime T: type, comptime sentinel: T, p: [*:sentinel]co
1153test "indexOfSentinel vector paths" {1153test "indexOfSentinel vector paths" {
1154 const Types = [_]type{ u8, u16, u32, u64 };1154 const Types = [_]type{ u8, u16, u32, u64 };
1155 const allocator = std.testing.allocator;1155 const allocator = std.testing.allocator;
1156 const page_size = std.heap.pageSize();1156 const page_size = std.heap.page_size_min;
11571157
1158 inline for (Types) |T| {1158 inline for (Types) |T| {
1159 const block_len = std.simd.suggestVectorLength(T) orelse continue;1159 const block_len = std.simd.suggestVectorLength(T) orelse continue;