From 3389947819b803dc87b01cb5d79a6954ba3afb0e Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Mon, 26 Jan 2026 09:08:27 -0500 Subject: [PATCH] Use each_line to avoid allocating array Though very unlikely, it could potentially allocate a large array of whitespace. --- lib/prism/lex_compat.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/prism/lex_compat.rb b/lib/prism/lex_compat.rb index 775be2759a..523ad39586 100644 --- a/lib/prism/lex_compat.rb +++ b/lib/prism/lex_compat.rb @@ -659,13 +659,14 @@ def result IgnoreStateToken.new([[lineno, column], event, value, lex_state]) when :on_words_sep # Ripper emits one token each per line. - lines = value.lines - lines[0...-1].each do |whitespace| - tokens << Token.new([[lineno, column], event, whitespace, lex_state]) - lineno += 1 - column = 0 + value.each_line.with_index do |line, index| + if index > 0 + lineno += 1 + column = 0 + end + tokens << Token.new([[lineno, column], event, line, lex_state]) end - Token.new([[lineno, column], event, lines.last, lex_state]) + tokens.pop when :on_regexp_end # On regex end, Ripper scans and then sets end state, so the ripper # lexed output is begin, when it should be end. prism sets lex state