Skip to content

Commit 62cc1a6

Browse files
committed
Use each_line to avoid allocating array
Though very unlikely, it could potentially allocate a large array of whitespace.
1 parent 6a67b0e commit 62cc1a6

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

lib/prism/lex_compat.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -659,13 +659,13 @@ def result
659659
IgnoreStateToken.new([[lineno, column], event, value, lex_state])
660660
when :on_words_sep
661661
# Ripper emits one token each per line.
662-
lines = value.lines
663-
lines[0...-1].each do |whitespace|
664-
tokens << Token.new([[lineno, column], event, whitespace, lex_state])
662+
value.each_line do |line|
663+
tokens << Token.new([[lineno, column], event, line, lex_state])
665664
lineno += 1
666665
column = 0
667666
end
668-
Token.new([[lineno, column], event, lines.last, lex_state])
667+
lineno -= 1
668+
tokens.pop
669669
when :on_regexp_end
670670
# On regex end, Ripper scans and then sets end state, so the ripper
671671
# lexed output is begin, when it should be end. prism sets lex state

0 commit comments

Comments
 (0)