zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit c8e807c44ed8c96b31a6cbe0b7f5f01a02ced270 (tree)
parent b14a350430aef737250b92520fa805201decf4d5
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Wed,  5 Feb 2025 13:21:15 -0800

std.heap.GeneralPurposeAllocator: use for loops in leak check

Diffstat:
Mlib/std/heap/general_purpose_allocator.zig | 9+++------
1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/lib/std/heap/general_purpose_allocator.zig b/lib/std/heap/general_purpose_allocator.zig @@ -412,12 +412,11 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { const size_class = @as(usize, 1) << @as(Log2USize, @intCast(size_class_index)); const slot_count = slot_counts[size_class_index]; var leaks = false; - var used_bits_byte: usize = 0; - while (used_bits_byte < used_bits_count) : (used_bits_byte += 1) { + for (0..used_bits_count) |used_bits_byte| { const used_byte = bucket.usedBits(used_bits_byte).*; if (used_byte != 0) { - var bit_index: u3 = 0; - while (true) : (bit_index += 1) { + for (0..8) |bit_index_usize| { + const bit_index: u3 = @intCast(bit_index_usize); const is_used = @as(u1, @truncate(used_byte >> bit_index)) != 0; if (is_used) { const slot_index: SlotIndex = @intCast(used_bits_byte * 8 + bit_index); @@ -427,8 +426,6 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { log.err("memory address 0x{x} leaked: {}", .{ addr, stack_trace }); leaks = true; } - if (bit_index == math.maxInt(u3)) - break; } } }