summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Valentine-House <matt@eightbitraptor.com>2024-01-16 16:06:18 +0000
committerKevin Newton <kddnewton@gmail.com>2024-01-16 12:43:53 -0500
commit7bd7030a96cdc106e347e0d48cfacfb80fb0f8db (patch)
treefbd3c5aa14e0130040c718cdb50df0440fa2c1e6
parent70a8ed0775e7a9215bcc6cdf4f6d85da321af304 (diff)
[PRISM] Replace local lookup recursion with loop
-rw-r--r--prism_compile.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/prism_compile.c b/prism_compile.c
index 9560232c1f..88362fa7ac 100644
--- a/prism_compile.c
+++ b/prism_compile.c
@@ -795,23 +795,18 @@ static pm_local_index_t
pm_lookup_local_index(rb_iseq_t *iseq, pm_scope_node_t *scope_node, pm_constant_id_t constant_id, int start_depth)
{
pm_local_index_t lindex = {0};
- int level = 0;
- if (start_depth) {
- level = start_depth;
- }
-
- if (!scope_node) {
- // We have recursed up all scope nodes
- // and have not found the local yet
- rb_bug("Local with constant_id %u does not exist", (unsigned int)constant_id);
- }
-
+ int level = (start_depth) ? start_depth : 0;
st_data_t local_index;
- if (!st_lookup(scope_node->index_lookup_table, constant_id, &local_index)) {
- // Local does not exist at this level, continue recursing up
+ while(!st_lookup(scope_node->index_lookup_table, constant_id, &local_index)) {
level++;
- return pm_lookup_local_index((rb_iseq_t *)ISEQ_BODY(iseq)->parent_iseq, scope_node->previous, constant_id, level);
+ if (scope_node->previous) {
+ scope_node = scope_node->previous;
+ } else {
+ // We have recursed up all scope nodes
+ // and have not found the local yet
+ rb_bug("Local with constant_id %u does not exist", (unsigned int)constant_id);
+ }
}
lindex.level = level;