diff options
| author | Kevin Newton <kddnewton@gmail.com> | 2024-04-05 13:43:19 -0400 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2024-04-05 19:24:01 +0000 |
| commit | 5e93cf9250bbdfeb409072ceaa29fa55fe2bd764 (patch) | |
| tree | 30c4c1b44be26f2461a32a4eeb06216b94417fb4 /prism | |
| parent | 3638aeb4cb0ae38ff915568d81da43b79b8d0dcd (diff) | |
[ruby/prism] Optimize pm_locals_order
https://github.com/ruby/prism/commit/13fe4e03c7
Diffstat (limited to 'prism')
| -rw-r--r-- | prism/prism.c | 7 |
1 files changed, 6 insertions, 1 deletions
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) { |
