pub fn put(self: *Map, key: []const u8, value: []const u8) Allocator.Error!void self: *Mapkey: []const u8value: []const u8257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272 pub fn put(self: *Map, key: []const u8, value: []const u8) Allocator.Error!void {
assert(validateKeyForPut(key));
const gpa = self.allocator;
const value_copy = try gpa.dupe(u8, value);
errdefer gpa.free(value_copy);
const get_or_put = try self.array_hash_map.getOrPut(gpa, key);
errdefer {
if (!get_or_put.found_existing) assert(self.array_hash_map.pop() != null);
}
if (get_or_put.found_existing) {
gpa.free(get_or_put.value_ptr.*);
} else {
get_or_put.key_ptr.* = try gpa.dupe(u8, key);
}
get_or_put.value_ptr.* = value_copy;
}
keyandvalueare copied into the Map.Asserts that
keyis valid:'\x00') byte.=, except on Windows where only the first code point is allowed to be=.