authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-05-29 15:30:56-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:47:56-07:00
logb336866fbc1edd4c999d3cd5d62ae7230d176fa7
tree7c99d4d707c360c51fc56189b2393068144b626d
parent804740af4ced8389e21df31a908c4212e32a477a

InternPool: avoid indexToKey recursion for ptr_elem,ptr_field

This is a hot function, and recursion makes it more difficult to profile, as well as likely making it more difficult to optimize.

1 files changed, 24 insertions(+), 12 deletions(-)

src/InternPool.zig+24-12
......@@ -2625,24 +2625,36 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
26252625 } };
26262626 },
26272627 .ptr_elem => {
2628 // Avoid `indexToKey` recursion by asserting the tag encoding.
26282629 const info = ip.extraData(PtrBaseIndex, data);
2629 return .{ .ptr = .{
2630 .ty = info.ty,
2631 .addr = .{ .elem = .{
2632 .base = info.base,
2633 .index = ip.indexToKey(info.index).int.storage.u64,
2630 const index_item = ip.items.get(@enumToInt(info.index));
2631 return switch (index_item.tag) {
2632 .int_usize => .{ .ptr = .{
2633 .ty = info.ty,
2634 .addr = .{ .elem = .{
2635 .base = info.base,
2636 .index = index_item.data,
2637 } },
26342638 } },
2635 } };
2639 .int_positive => @panic("TODO"), // implement along with behavior test coverage
2640 else => unreachable,
2641 };
26362642 },
26372643 .ptr_field => {
2644 // Avoid `indexToKey` recursion by asserting the tag encoding.
26382645 const info = ip.extraData(PtrBaseIndex, data);
2639 return .{ .ptr = .{
2640 .ty = info.ty,
2641 .addr = .{ .field = .{
2642 .base = info.base,
2643 .index = ip.indexToKey(info.index).int.storage.u64,
2646 const index_item = ip.items.get(@enumToInt(info.index));
2647 return switch (index_item.tag) {
2648 .int_usize => .{ .ptr = .{
2649 .ty = info.ty,
2650 .addr = .{ .field = .{
2651 .base = info.base,
2652 .index = index_item.data,
2653 } },
26442654 } },
2645 } };
2655 .int_positive => @panic("TODO"), // implement along with behavior test coverage
2656 else => unreachable,
2657 };
26462658 },
26472659 .ptr_slice => {
26482660 const info = ip.extraData(PtrSlice, data);