summaryrefslogtreecommitdiff
path: root/iseq.c
diff options
context:
space:
mode:
authorAaron Patterson <[email protected]>2024-01-12 14:21:35 -0800
committerAaron Patterson <[email protected]>2024-01-12 14:53:14 -0800
commit475663f0399248011f2392817ef4d89ec07baae4 (patch)
tree1b04d2bcd4f64c20eae47a8b1ecf2246d35bbfa1 /iseq.c
parent206388b19eb3e1d98ee77821a96705c97c86eb06 (diff)
Only intern constants upon compilation entry
Before this commit the Prism compiler would try to intern constants every time it re-entered. This pool of constants is "constant" (there is only one pool per parser instance), so we should do it only once: upon the top level entry to the compiler. This change does just that: it populates the interned constants once. Fixes: https://github.com/ruby/prism/issues/2152
Diffstat (limited to 'iseq.c')
-rw-r--r--iseq.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/iseq.c b/iseq.c
index f2911b43f2..3b87cdcc78 100644
--- a/iseq.c
+++ b/iseq.c
@@ -1430,10 +1430,20 @@ iseqw_s_compile_prism_compile(pm_parser_t *parser, VALUE opt, rb_iseq_t *iseq, V
pm_scope_node_t scope_node;
pm_scope_node_init(node, &scope_node, NULL, parser);
+
+ ID *constants = calloc(parser->constant_pool.size, sizeof(ID));
+ rb_encoding *encoding = rb_enc_find(parser->encoding->name);
+ for (uint32_t index = 0; index < parser->constant_pool.size; index++) {
+ pm_constant_t *constant = &parser->constant_pool.constants[index];
+ constants[index] = rb_intern3((const char *) constant->start, constant->length, encoding);
+ }
+ scope_node.constants = constants;
+
rb_iseq_compile_prism_node(iseq, &scope_node, parser);
finish_iseq_build(iseq);
pm_node_destroy(parser, node);
+ free(constants);
}
}