pub fn putMove(self: *BufMap, key: []u8, value: []u8) !void self: *BufMapkey: []u8value: []u836
37
38
39
40
41
42
43
44 pub fn putMove(self: *BufMap, key: []u8, value: []u8) !void {
const get_or_put = try self.hash_map.getOrPut(key);
if (get_or_put.found_existing) {
self.free(get_or_put.key_ptr.*);
self.free(get_or_put.value_ptr.*);
get_or_put.key_ptr.* = key;
}
get_or_put.value_ptr.* = value;
}
Same as
putbut the key and value become owned by the BufMap rather than being copied. IfputMovefails, the ownership of key and value does not transfer.