Skip to content

Commit

Permalink
macho: cache Attr by-at value
Browse files Browse the repository at this point in the history
  • Loading branch information
kubkon committed Nov 24, 2023
1 parent e8e47d1 commit 0b810d1
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/MachO/DwarfInfo.zig
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ fn parseAbbrevTables(dw: *DwarfInfo, allocator: Allocator) !void {
const form = try leb.readULEB128(u64, reader);
if (at == 0 and form == 0) break;

const attr = try decl.attrs.addOne(allocator);
try decl.attrs.ensureUnusedCapacity(allocator, 1);
const attr_gop = decl.attrs.getOrPutAssumeCapacity(at);
assert(!attr_gop.found_existing);
const attr = attr_gop.value_ptr;
attr.* = .{
.at = at,
.form = form,
Expand Down Expand Up @@ -139,9 +142,9 @@ fn parseDebugInfoEntry(

const decl = table.decls.get(code) orelse return error.MalformedDwarf; // TODO better errors
const data = dw.debug_info;
try cu.diePtr(die).values.ensureTotalCapacityPrecise(allocator, decl.attrs.items.len);
try cu.diePtr(die).values.ensureTotalCapacityPrecise(allocator, decl.attrs.values().len);

for (decl.attrs.items) |attr| {
for (decl.attrs.values()) |attr| {
const start = creader.bytes_read;
try advanceByFormSize(cu, attr.form, creader);
const end = creader.bytes_read;
Expand Down Expand Up @@ -259,7 +262,7 @@ pub const AbbrevTable = struct {
code: u64,
tag: u64,
children: bool,
attrs: std.ArrayListUnmanaged(Attr) = .{},
attrs: std.AutoArrayHashMapUnmanaged(u64, Attr) = .{},
loc: Loc,

pub fn deinit(decl: *Decl, gpa: Allocator) void {
Expand Down Expand Up @@ -389,9 +392,10 @@ pub const CompileUnit = struct {
const table = dw.abbrev_tables.get(cu.header.debug_abbrev_offset) orelse return null;
for (cu.dies.items) |die| {
const decl = table.decls.get(die.code).?;
for (die.values.items, decl.attrs.items) |value, attr| {
if (attr.at == at) return .{ attr, value };
}
const index = decl.attrs.getIndex(at) orelse return null;
const attr = decl.attrs.values()[index];
const value = die.values.items[index];
return .{ attr, value };
}
return null;
}
Expand Down

0 comments on commit 0b810d1

Please sign in to comment.