authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-04-02 19:10:09-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-04-02 19:18:41-07:00
log843d5adcd6ec0b620fe93e0366aa0e8bb92bd171
tree9fe1bc1f74c64be681f2b140aea477e482289164
parent3b32e0be3187d8815ce20dd6b45665dc4e85b443

std.ArrayHashMap: lazier verifyContext calls

Companion commit to b45c6c757cb4a16f5021c8bf057d14183036f14c. Related: #11367

1 files changed, 8 insertions(+), 2 deletions(-)

lib/std/array_hash_map.zig+8-2
......@@ -77,12 +77,15 @@ pub fn ArrayHashMap(
7777 comptime Context: type,
7878 comptime store_hash: bool,
7979) type {
80 comptime std.hash_map.verifyContext(Context, K, K, u32, true);
8180 return struct {
8281 unmanaged: Unmanaged,
8382 allocator: Allocator,
8483 ctx: Context,
8584
85 comptime {
86 std.hash_map.verifyContext(Context, K, K, u32, true);
87 }
88
8689 /// The ArrayHashMapUnmanaged type using the same settings as this managed map.
8790 pub const Unmanaged = ArrayHashMapUnmanaged(K, V, Context, store_hash);
8891
......@@ -470,7 +473,6 @@ pub fn ArrayHashMapUnmanaged(
470473 comptime Context: type,
471474 comptime store_hash: bool,
472475) type {
473 comptime std.hash_map.verifyContext(Context, K, K, u32, true);
474476 return struct {
475477 /// It is permitted to access this field directly.
476478 entries: DataList = .{},
......@@ -481,6 +483,10 @@ pub fn ArrayHashMapUnmanaged(
481483 /// by how many total indexes there are.
482484 index_header: ?*IndexHeader = null,
483485
486 comptime {
487 std.hash_map.verifyContext(Context, K, K, u32, true);
488 }
489
484490 /// Modifying the key is allowed only if it does not change the hash.
485491 /// Modifying the value is allowed.
486492 /// Entry pointers become invalid whenever this ArrayHashMap is modified,