diff options
| author | Earlopain <14981592+Earlopain@users.noreply.github.com> | 2025-03-11 10:30:39 +0100 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2025-03-13 13:52:45 +0000 |
| commit | 3d4c7c38020fa4de420e927e0b579aeff62b54ba (patch) | |
| tree | 75c51c67862fa07c899630d89692ca805a54eeaa | |
| parent | 67e6ccb23fd910b70b0d690adcb56395778c9f2a (diff) | |
[ruby/prism] Use `reverse_each` in the parser translator
Avoids an array allocation which matters more and more
the larger the file is.
I have it at 14% of runtime.
https://github.com/ruby/prism/commit/f65b90f27d
| -rw-r--r-- | lib/prism/translation/parser/lexer.rb | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/prism/translation/parser/lexer.rb b/lib/prism/translation/parser/lexer.rb index 0d247be117..cc063e88d0 100644 --- a/lib/prism/translation/parser/lexer.rb +++ b/lib/prism/translation/parser/lexer.rb @@ -261,10 +261,11 @@ module Prism case type when :kDO - types = tokens.map(&:first) - nearest_lambda_token_type = types.reverse.find { |type| LAMBDA_TOKEN_TYPES.include?(type) } + nearest_lambda_token = tokens.reverse_each.find do |token| + LAMBDA_TOKEN_TYPES.include?(token.first) + end - if nearest_lambda_token_type == :tLAMBDA + if nearest_lambda_token&.first == :tLAMBDA type = :kDO_LAMBDA end when :tCHARACTER |
