pub fn putMove(self: *Map, key: []u8, value: []u8) Allocator.Error!void self: *Mapkey: []u8value: []u8238
239
240
241
242
243
244
245
246
247
248 pub fn putMove(self: *Map, key: []u8, value: []u8) Allocator.Error!void {
assert(validateKeyForPut(key));
const gpa = self.allocator;
const get_or_put = try self.array_hash_map.getOrPut(gpa, key);
if (get_or_put.found_existing) {
gpa.free(get_or_put.key_ptr.*);
gpa.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 Map rather than being copied. IfputMovefails, the ownership of key and value does not transfer.Asserts that
keyis valid:'\x00') byte.=, except on Windows where only the first code point is allowed to be=.