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(...@@ -77,12 +77,15 @@ pub fn ArrayHashMap(
77 comptime Context: type,77 comptime Context: type,
78 comptime store_hash: bool,78 comptime store_hash: bool,
79) type {79) type {
80 comptime std.hash_map.verifyContext(Context, K, K, u32, true);
81 return struct {80 return struct {
82 unmanaged: Unmanaged,81 unmanaged: Unmanaged,
83 allocator: Allocator,82 allocator: Allocator,
84 ctx: Context,83 ctx: Context,
8584
85 comptime {
86 std.hash_map.verifyContext(Context, K, K, u32, true);
87 }
88
86 /// The ArrayHashMapUnmanaged type using the same settings as this managed map.89 /// The ArrayHashMapUnmanaged type using the same settings as this managed map.
87 pub const Unmanaged = ArrayHashMapUnmanaged(K, V, Context, store_hash);90 pub const Unmanaged = ArrayHashMapUnmanaged(K, V, Context, store_hash);
8891
...@@ -470,7 +473,6 @@ pub fn ArrayHashMapUnmanaged(...@@ -470,7 +473,6 @@ pub fn ArrayHashMapUnmanaged(
470 comptime Context: type,473 comptime Context: type,
471 comptime store_hash: bool,474 comptime store_hash: bool,
472) type {475) type {
473 comptime std.hash_map.verifyContext(Context, K, K, u32, true);
474 return struct {476 return struct {
475 /// It is permitted to access this field directly.477 /// It is permitted to access this field directly.
476 entries: DataList = .{},478 entries: DataList = .{},
...@@ -481,6 +483,10 @@ pub fn ArrayHashMapUnmanaged(...@@ -481,6 +483,10 @@ pub fn ArrayHashMapUnmanaged(
481 /// by how many total indexes there are.483 /// by how many total indexes there are.
482 index_header: ?*IndexHeader = null,484 index_header: ?*IndexHeader = null,
483485
486 comptime {
487 std.hash_map.verifyContext(Context, K, K, u32, true);
488 }
489
484 /// Modifying the key is allowed only if it does not change the hash.490 /// Modifying the key is allowed only if it does not change the hash.
485 /// Modifying the value is allowed.491 /// Modifying the value is allowed.
486 /// Entry pointers become invalid whenever this ArrayHashMap is modified,492 /// Entry pointers become invalid whenever this ArrayHashMap is modified,