mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
std.ArrayHashMap: allow passing empty values array
in which case the values array is set to undefined
This commit is contained in:
parent
91efc5c98b
commit
3cb00c5bcd
@ -641,10 +641,13 @@ pub fn ArrayHashMapUnmanaged(
|
||||
return self;
|
||||
}
|
||||
|
||||
/// An empty `value_list` may be passed, in which case the values array becomes `undefined`.
|
||||
pub fn reinit(self: *Self, gpa: Allocator, key_list: []const K, value_list: []const V) Oom!void {
|
||||
try self.entries.resize(gpa, key_list.len);
|
||||
@memcpy(self.keys(), key_list);
|
||||
if (@sizeOf(V) != 0) {
|
||||
if (value_list.len == 0) {
|
||||
@memset(self.values(), undefined);
|
||||
} else {
|
||||
assert(key_list.len == value_list.len);
|
||||
@memcpy(self.values(), value_list);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user