[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
This commit is contained in:
Earlopain 2025-03-11 10:30:39 +01:00 committed by git
parent 67e6ccb23f
commit 3d4c7c3802

View File

@ -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