aboutsummaryrefslogtreecommitdiff
path: root/src/AstGen.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-04-20 22:16:45 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-04-20 22:16:45 -0700
commitd10ec6e70dbcf49ba14be549069271e564fec76b (patch)
treeaaf536d93d9e7db99c7c507ae571730fa7331f01 /src/AstGen.zig
parenta1ac2b95bb9d6b98c6ae862bda31c84721b92bf3 (diff)
downloadzig-d10ec6e70dbcf49ba14be549069271e564fec76b.tar.gz
zig-d10ec6e70dbcf49ba14be549069271e564fec76b.zip
AstGen: slightly better eager-allocating heuristic
Some early ensureCapacity calls to avoid needless reallocations.
Diffstat (limited to 'src/AstGen.zig')
-rw-r--r--src/AstGen.zig8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig
index 782ed7f749..49861cd145 100644
--- a/src/AstGen.zig
+++ b/src/AstGen.zig
@@ -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,