[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:
parent
67e6ccb23f
commit
3d4c7c3802
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user