diff options
| author | Jacob Young <15544577+jacobly0@users.noreply.github.com> | 2025-06-01 22:02:34 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-01 22:02:34 -0400 |
| commit | 8dbd29cc4588cf118532a816d74b78f62999b636 (patch) | |
| tree | 0fc19e694d1ad7366dd2b7153dd0d4647d3a9159 /lib/std/array_hash_map.zig | |
| parent | 0386730777da858908aaba4ef96fb5bd48faafc9 (diff) | |
| parent | 6a63c8653ae9121f1cbcee49d32ec4f8deaf0b65 (diff) | |
| download | zig-8dbd29cc4588cf118532a816d74b78f62999b636.tar.gz zig-8dbd29cc4588cf118532a816d74b78f62999b636.zip | |
Merge pull request #24011 from jacobly0/legalize-unary
Legalize: implement scalarization and safety check expansion
Diffstat (limited to 'lib/std/array_hash_map.zig')
| -rw-r--r-- | lib/std/array_hash_map.zig | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/lib/std/array_hash_map.zig b/lib/std/array_hash_map.zig index b0b9e19169..ac9c70df8e 100644 --- a/lib/std/array_hash_map.zig +++ b/lib/std/array_hash_map.zig @@ -889,19 +889,10 @@ pub fn ArrayHashMapUnmanaged( self.pointer_stability.lock(); defer self.pointer_stability.unlock(); - if (new_capacity <= linear_scan_max) { - try self.entries.ensureTotalCapacity(gpa, new_capacity); - return; - } - - if (self.index_header) |header| { - if (new_capacity <= header.capacity()) { - try self.entries.ensureTotalCapacity(gpa, new_capacity); - return; - } - } - try self.entries.ensureTotalCapacity(gpa, new_capacity); + if (new_capacity <= linear_scan_max) return; + if (self.index_header) |header| if (new_capacity <= header.capacity()) return; + const new_bit_index = try IndexHeader.findBitIndex(new_capacity); const new_header = try IndexHeader.alloc(gpa, new_bit_index); @@ -2116,7 +2107,7 @@ const IndexHeader = struct { fn findBitIndex(desired_capacity: usize) Allocator.Error!u8 { if (desired_capacity > max_capacity) return error.OutOfMemory; - var new_bit_index = @as(u8, @intCast(std.math.log2_int_ceil(usize, desired_capacity))); + var new_bit_index: u8 = @intCast(std.math.log2_int_ceil(usize, desired_capacity)); if (desired_capacity > index_capacities[new_bit_index]) new_bit_index += 1; if (new_bit_index < min_bit_index) new_bit_index = min_bit_index; assert(desired_capacity <= index_capacities[new_bit_index]); |
