aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-05-29 15:30:56 -0700
committerAndrew Kelley <andrew@ziglang.org>2023-06-10 20:47:56 -0700
commitb336866fbc1edd4c999d3cd5d62ae7230d176fa7 (patch)
tree7c99d4d707c360c51fc56189b2393068144b626d /src
parent804740af4ced8389e21df31a908c4212e32a477a (diff)
downloadzig-b336866fbc1edd4c999d3cd5d62ae7230d176fa7.tar.gz
zig-b336866fbc1edd4c999d3cd5d62ae7230d176fa7.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/InternPool.zig36
1 files changed, 24 insertions, 12 deletions
diff --git a/src/InternPool.zig b/src/InternPool.zig
index 008f0f4df1..f1acbdfebf 100644
--- a/src/InternPool.zig
+++ b/src/InternPool.zig
@@ -2625,24 +2625,36 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
} };
},
.ptr_elem => {
+ // Avoid `indexToKey` recursion by asserting the tag encoding.
const info = ip.extraData(PtrBaseIndex, data);
- return .{ .ptr = .{
- .ty = info.ty,
- .addr = .{ .elem = .{
- .base = info.base,
- .index = ip.indexToKey(info.index).int.storage.u64,
+ const index_item = ip.items.get(@enumToInt(info.index));
+ return switch (index_item.tag) {
+ .int_usize => .{ .ptr = .{
+ .ty = info.ty,
+ .addr = .{ .elem = .{
+ .base = info.base,
+ .index = index_item.data,
+ } },
} },
- } };
+ .int_positive => @panic("TODO"), // implement along with behavior test coverage
+ else => unreachable,
+ };
},
.ptr_field => {
+ // Avoid `indexToKey` recursion by asserting the tag encoding.
const info = ip.extraData(PtrBaseIndex, data);
- return .{ .ptr = .{
- .ty = info.ty,
- .addr = .{ .field = .{
- .base = info.base,
- .index = ip.indexToKey(info.index).int.storage.u64,
+ const index_item = ip.items.get(@enumToInt(info.index));
+ return switch (index_item.tag) {
+ .int_usize => .{ .ptr = .{
+ .ty = info.ty,
+ .addr = .{ .field = .{
+ .base = info.base,
+ .index = index_item.data,
+ } },
} },
- } };
+ .int_positive => @panic("TODO"), // implement along with behavior test coverage
+ else => unreachable,
+ };
},
.ptr_slice => {
const info = ip.extraData(PtrSlice, data);