Skip to content

Commit

Permalink
Merge pull request #1275 from froydnj/froydnj-ast-ary-capa
Browse files Browse the repository at this point in the history
preallocate arrays when building the Ruby AST
  • Loading branch information
jemmaissroff authored Aug 17, 2023
2 parents c57436c + c2e92e9 commit bf10d91
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions templates/ext/yarp/api_node.c.erb
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,22 @@ yp_ast_new(yp_parser_t *parser, yp_node_t *node, rb_encoding *encoding) {
<%- when NodeParam, OptionalNodeParam -%>
argv[<%= index %>] = rb_ary_pop(value_stack);
<%- when NodeListParam -%>
argv[<%= index %>] = rb_ary_new();
argv[<%= index %>] = rb_ary_new_capa(cast-><%= param.name %>.size);
for (size_t index = 0; index < cast-><%= param.name %>.size; index++) {
rb_ary_push(argv[<%= index %>], rb_ary_pop(value_stack));
}
<%- when StringParam -%>
argv[<%= index %>] = yp_string_new(&cast-><%= param.name %>, encoding);
<%- when LocationListParam -%>
argv[<%= index %>] = rb_ary_new();
argv[<%= index %>] = rb_ary_new_capa(cast-><%= param.name %>.size);
for (size_t index = 0; index < cast-><%= param.name %>.size; index++) {
yp_location_t location = cast-><%= param.name %>.locations[index];
rb_ary_push(argv[<%= index %>], yp_location_new(parser, location.start, location.end, source));
}
<%- when ConstantParam -%>
argv[<%= index %>] = rb_id2sym(constants[cast-><%= param.name %> - 1]);
<%- when ConstantListParam -%>
argv[<%= index %>] = rb_ary_new();
argv[<%= index %>] = rb_ary_new_capa(cast-><%= param.name %>.size);
for (size_t index = 0; index < cast-><%= param.name %>.size; index++) {
rb_ary_push(argv[<%= index %>], rb_id2sym(constants[cast-><%= param.name %>.ids[index] - 1]));
}
Expand Down

0 comments on commit bf10d91

Please sign in to comment.