From c4456e7e2f0699be410a0e6014ebf040a03766b1 Mon Sep 17 00:00:00 2001 From: Techatrix Date: Sun, 22 Dec 2024 01:28:29 +0100 Subject: [PATCH] optimize collectCImportNodes --- src/analysis.zig | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/analysis.zig b/src/analysis.zig index e962232d2..76ac1821e 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -3110,16 +3110,20 @@ pub fn collectCImportNodes(allocator: std.mem.Allocator, tree: Ast) error{OutOfM errdefer import_nodes.deinit(allocator); const node_tags = tree.nodes.items(.tag); - const main_tokens = tree.nodes.items(.main_token); - - var i: usize = 0; - while (i < node_tags.len) : (i += 1) { - const node: Ast.Node.Index = @intCast(i); - if (!ast.isBuiltinCall(tree, node)) continue; + for (node_tags, 0..) |tag, node| { + switch (tag) { + .builtin_call, + .builtin_call_comma, + .builtin_call_two, + .builtin_call_two_comma, + => {}, + else => continue, + } + const main_tokens = tree.nodes.items(.main_token); if (!std.mem.eql(u8, Ast.tokenSlice(tree, main_tokens[node]), "@cImport")) continue; - try import_nodes.append(allocator, node); + try import_nodes.append(allocator, @intCast(node)); } return import_nodes.toOwnedSlice(allocator);