Skip to content

Commit f65b90f

Browse files
committed
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.
1 parent ca9500a commit f65b90f

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

lib/prism/translation/parser/lexer.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,11 @@ def to_a
262262

263263
case type
264264
when :kDO
265-
types = tokens.map(&:first)
266-
nearest_lambda_token_type = types.reverse.find { |type| LAMBDA_TOKEN_TYPES.include?(type) }
265+
nearest_lambda_token = tokens.reverse_each.find do |token|
266+
LAMBDA_TOKEN_TYPES.include?(token.first)
267+
end
267268

268-
if nearest_lambda_token_type == :tLAMBDA
269+
if nearest_lambda_token&.first == :tLAMBDA
269270
type = :kDO_LAMBDA
270271
end
271272
when :tCHARACTER

0 commit comments

Comments
 (0)