| ... | @@ -1559,9 +1559,9 @@ pub fn HashMapUnmanaged( | ... | @@ -1559,9 +1559,9 @@ pub fn HashMapUnmanaged( |
| 1559 | assert(std.math.isPowerOfTwo(new_cap)); | 1559 | assert(std.math.isPowerOfTwo(new_cap)); |
| 1560 | | 1560 | |
| 1561 | var map: Self = .{}; | 1561 | var map: Self = .{}; |
| 1562 | defer map.deinit(allocator); | | |
| 1563 | map.pointer_stability.lock(); | | |
| 1564 | try map.allocate(allocator, new_cap); | 1562 | try map.allocate(allocator, new_cap); |
| | 1563 | errdefer comptime unreachable; |
| | 1564 | map.pointer_stability.lock(); |
| 1565 | map.initMetadatas(); | 1565 | map.initMetadatas(); |
| 1566 | map.available = @truncate((new_cap * max_load_percentage) / 100); | 1566 | map.available = @truncate((new_cap * max_load_percentage) / 100); |
| 1567 | | 1567 | |
| ... | @@ -1581,6 +1581,7 @@ pub fn HashMapUnmanaged( | ... | @@ -1581,6 +1581,7 @@ pub fn HashMapUnmanaged( |
| 1581 | self.size = 0; | 1581 | self.size = 0; |
| 1582 | self.pointer_stability = .{ .state = .unlocked }; | 1582 | self.pointer_stability = .{ .state = .unlocked }; |
| 1583 | std.mem.swap(Self, self, &map); | 1583 | std.mem.swap(Self, self, &map); |
| | 1584 | map.deinit(allocator); |
| 1584 | } | 1585 | } |
| 1585 | | 1586 | |
| 1586 | fn allocate(self: *Self, allocator: Allocator, new_capacity: Size) Allocator.Error!void { | 1587 | fn allocate(self: *Self, allocator: Allocator, new_capacity: Size) Allocator.Error!void { |
| ... | @@ -2266,3 +2267,8 @@ test "repeat fetchRemove" { | ... | @@ -2266,3 +2267,8 @@ test "repeat fetchRemove" { |
| 2266 | try testing.expect(map.get(2) != null); | 2267 | try testing.expect(map.get(2) != null); |
| 2267 | try testing.expect(map.get(3) != null); | 2268 | try testing.expect(map.get(3) != null); |
| 2268 | } | 2269 | } |
| | 2270 | |
| | 2271 | test "getOrPut allocation failure" { |
| | 2272 | var map: std.StringHashMapUnmanaged(void) = .{}; |
| | 2273 | try testing.expectError(error.OutOfMemory, map.getOrPut(std.testing.failing_allocator, "hello")); |
| | 2274 | } |