| ... | @@ -39,6 +39,7 @@ pub const BufMap = struct { | ... | @@ -39,6 +39,7 @@ pub const BufMap = struct { |
| 39 | const get_or_put = try self.hash_map.getOrPut(key); | 39 | const get_or_put = try self.hash_map.getOrPut(key); |
| 40 | if (get_or_put.found_existing) { | 40 | if (get_or_put.found_existing) { |
| 41 | self.free(get_or_put.entry.key); | 41 | self.free(get_or_put.entry.key); |
| | 42 | self.free(get_or_put.entry.value); |
| 42 | get_or_put.entry.key = key; | 43 | get_or_put.entry.key = key; |
| 43 | } | 44 | } |
| 44 | get_or_put.entry.value = value; | 45 | get_or_put.entry.value = value; |
| ... | @@ -88,7 +89,8 @@ pub const BufMap = struct { | ... | @@ -88,7 +89,8 @@ pub const BufMap = struct { |
| 88 | }; | 89 | }; |
| 89 | | 90 | |
| 90 | test "BufMap" { | 91 | test "BufMap" { |
| 91 | var bufmap = BufMap.init(std.testing.allocator); | 92 | const allocator = std.testing.allocator; |
| | 93 | var bufmap = BufMap.init(allocator); |
| 92 | defer bufmap.deinit(); | 94 | defer bufmap.deinit(); |
| 93 | | 95 | |
| 94 | try bufmap.set("x", "1"); | 96 | try bufmap.set("x", "1"); |
| ... | @@ -105,4 +107,7 @@ test "BufMap" { | ... | @@ -105,4 +107,7 @@ test "BufMap" { |
| 105 | | 107 | |
| 106 | bufmap.delete("x"); | 108 | bufmap.delete("x"); |
| 107 | testing.expect(0 == bufmap.count()); | 109 | testing.expect(0 == bufmap.count()); |
| | 110 | |
| | 111 | try bufmap.setMove(try allocator.dupe(u8, "k"), try allocator.dupe(u8, "v1")); |
| | 112 | try bufmap.setMove(try allocator.dupe(u8, "k"), try allocator.dupe(u8, "v2")); |
| 108 | } | 113 | } |