From 3cb00c5bcd3dec191bea0cbab9fcac77c0e3a910 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 18 Dec 2024 18:24:55 -0800 Subject: [PATCH] std.ArrayHashMap: allow passing empty values array in which case the values array is set to undefined --- lib/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 index 4e18aecf9d..22c736d0a5 100644 --- 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); }