mirror of
https://github.com/ziglang/zig.git
synced 2025-12-31 02:23:22 +00:00
AstGen: slightly better eager-allocating heuristic
Some early ensureCapacity calls to avoid needless reallocations.
This commit is contained in:
parent
a1ac2b95bb
commit
d10ec6e70d
@ -81,8 +81,14 @@ pub fn generate(gpa: *Allocator, file: *Scope.File) InnerError!Zir {
|
||||
};
|
||||
defer astgen.deinit(gpa);
|
||||
|
||||
// We expect at least as many ZIR instructions and extra data items
|
||||
// as AST nodes.
|
||||
try astgen.instructions.ensureTotalCapacity(gpa, file.tree.nodes.len);
|
||||
|
||||
// First few indexes of extra are reserved and set at the end.
|
||||
try astgen.extra.resize(gpa, @typeInfo(Zir.ExtraIndex).Enum.fields.len);
|
||||
const reserved_count = @typeInfo(Zir.ExtraIndex).Enum.fields.len;
|
||||
try astgen.extra.ensureTotalCapacity(gpa, file.tree.nodes.len + reserved_count);
|
||||
astgen.extra.items.len += reserved_count;
|
||||
|
||||
var gen_scope: GenZir = .{
|
||||
.force_comptime = true,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user