From 5e93cf9250bbdfeb409072ceaa29fa55fe2bd764 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Fri, 5 Apr 2024 13:43:19 -0400 Subject: [ruby/prism] Optimize pm_locals_order https://github.com/ruby/prism/commit/13fe4e03c7 --- prism/prism.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/prism/prism.c b/prism/prism.c index 0d5429e16a..c5d33005cf 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -1011,7 +1011,12 @@ static void pm_locals_order(PRISM_ATTRIBUTE_UNUSED pm_parser_t *parser, pm_locals_t *locals, pm_constant_id_list_t *list, bool warn_unused) { pm_constant_id_list_init_capacity(list, locals->size); - for (uint32_t index = 0; index < locals->capacity; index++) { + // If we're still below the threshold for switching to a hash, then we only + // need to loop over the locals until we hit the size because the locals are + // stored in a list. + uint32_t capacity = locals->capacity < PM_LOCALS_HASH_THRESHOLD ? locals->size : locals->capacity; + + for (uint32_t index = 0; index < capacity; index++) { pm_local_t *local = &locals->locals[index]; if (local->name != PM_CONSTANT_ID_UNSET) { -- cgit v1.2.3