diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-07-28 00:00:35 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-07-28 00:00:35 -0700 |
| commit | c37f273cb053f50bb39ec36fcfeef284adf0a342 (patch) | |
| tree | 778ef441e488dcb863da09f3c61861d9f78051eb | |
| parent | 0965724e31666d156ca96375eee591380f3c9042 (diff) | |
| download | zig-c37f273cb053f50bb39ec36fcfeef284adf0a342.tar.gz zig-c37f273cb053f50bb39ec36fcfeef284adf0a342.zip | |
stage1: hot path for resolving types of primitives
This is an attempt to save memory when building self-hosted.
before:
Total bytes allocated: 5.941 GiB, deallocated: 2.259 GiB, remaining: 3.681 GiB
after:
Total bytes allocated: 5.933 GiB, deallocated: 2.253 GiB, remaining: 3.680 GiB
| -rw-r--r-- | src/analyze.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp index 66f3f28b50..e3e57ee34d 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -1490,6 +1490,20 @@ static OnePossibleValue type_val_resolve_has_one_possible_value(CodeGen *g, ZigV } ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) { + Error err; + // Hot path for simple identifiers, to avoid unnecessary memory allocations. + if (node->type == NodeTypeSymbol) { + Buf *variable_name = node->data.symbol_expr.symbol; + if (buf_eql_str(variable_name, "_")) + goto abort_hot_path; + ZigType *primitive_type; + if ((err = get_primitive_type(g, variable_name, &primitive_type))) { + goto abort_hot_path; + } else { + return primitive_type; + } +abort_hot_path:; + } ZigValue *result = analyze_const_value(g, scope, node, g->builtin_types.entry_type, nullptr, UndefBad); if (type_is_invalid(result->type)) |
