zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 3cb00c5bcd3dec191bea0cbab9fcac77c0e3a910 (tree)
parent 91efc5c98bb32f3b1d42895362d5ae5a175a1345
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Wed, 18 Dec 2024 18:24:55 -0800

std.ArrayHashMap: allow passing empty values array

in which case the values array is set to undefined

Diffstat:
Mlib/std/array_hash_map.zig | 5++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/std/array_hash_map.zig b/lib/std/array_hash_map.zig @@ -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); }