authorgravatar for marko03kostic@protonmail.commarko <marko03kostic@protonmail.com> 2025-09-11 00:14:01+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-09-11 00:18:37-07:00
logfb3afc8d3da547c1b73c9cf18cd1a394b0ebefbc
treea2cbdbab26ea7af03443bc58839a53e5759b52c2
parentbfda12efcf2f6b4bc6803f520108b7ce05636965

use pointer subtraction


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

lib/std/hash_map.zig+1-2
......@@ -1267,12 +1267,11 @@ pub fn HashMapUnmanaged(
12671267 /// TODO: answer the question in these doc comments, does this
12681268 /// increase the unused capacity by one?
12691269 pub fn removeByPtr(self: *Self, key_ptr: *K) void {
1270 // TODO: replace with pointer subtraction once supported by zig
12711270 // if @sizeOf(K) == 0 then there is at most one item in the hash
12721271 // map, which is assumed to exist as key_ptr must be valid. This
12731272 // item must be at index 0.
12741273 const idx = if (@sizeOf(K) > 0)
1275 (@intFromPtr(key_ptr) - @intFromPtr(self.keys())) / @sizeOf(K)
1274 (key_ptr - self.keys())
12761275 else
12771276 0;
12781277