aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLee Cannon <leecannon@leecannon.xyz>2021-10-31 15:06:55 +0000
committerAndrew Kelley <andrew@ziglang.org>2021-10-31 18:11:53 -0400
commit83dcfd62053a80024b1cb282fddf399a36c9c58e (patch)
treec26750b6c78a782534d4a6c5fa1b7fc6737b0c0f /src
parent8346e011c9ecbd7d462f0948d2e9dfc7e4067482 (diff)
downloadzig-83dcfd62053a80024b1cb282fddf399a36c9c58e.tar.gz
zig-83dcfd62053a80024b1cb282fddf399a36c9c58e.zip
optimize AstGen.callExpr
Diffstat (limited to 'src')
-rw-r--r--src/AstGen.zig10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig
index 509880ec95..b7ab74ed4a 100644
--- a/src/AstGen.zig
+++ b/src/AstGen.zig
@@ -7975,8 +7975,14 @@ fn callExpr(
const callee = try calleeExpr(gz, scope, call.ast.fn_expr);
- const args = try astgen.gpa.alloc(Zir.Inst.Ref, call.ast.params.len);
- defer astgen.gpa.free(args);
+ // A large proportion of calls have 5 or less arguments, due to this preventing allocations
+ // for calls with few arguments has a sizeable effect on the aggregated runtime of this function
+ var arg_buffer: [5]Zir.Inst.Ref = undefined;
+ const args: []Zir.Inst.Ref = if (call.ast.params.len <= arg_buffer.len)
+ arg_buffer[0..call.ast.params.len]
+ else
+ try astgen.gpa.alloc(Zir.Inst.Ref, call.ast.params.len);
+ defer if (call.ast.params.len > arg_buffer.len) astgen.gpa.free(args);
for (call.ast.params) |param_node, i| {
// Parameters are always temporary values, they have no