ruby-changes:70012
From: schneems <ko1@a...>
Date: Thu, 2 Dec 2021 15:55:54 +0900 (JST)
Subject: [ruby-changes:70012] 3685b5af95 (master): Only iterate Lexer heredoc arrays
https://git.ruby-lang.org/ruby.git/commit/?id=3685b5af95 From 3685b5af95fc31b99b34a5a4f75bdc7c0ba622f4 Mon Sep 17 00:00:00 2001 From: schneems <richard.schneeman+foo@g...> Date: Sun, 7 Nov 2021 20:30:50 -0600 Subject: Only iterate Lexer heredoc arrays The last element in the `@buf` may be either an array or an `Elem`. In the case it is an `Elem` we iterate over every element, when we do not need to. This check guards that case by ensuring that we only iterate over an array of elements. --- ext/ripper/lib/ripper/lexer.rb | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/ext/ripper/lib/ripper/lexer.rb b/ext/ripper/lib/ripper/lexer.rb index 92ee4ef7df3..a2d4d655b5b 100644 --- a/ext/ripper/lib/ripper/lexer.rb +++ b/ext/ripper/lib/ripper/lexer.rb @@ -166,17 +166,19 @@ class Ripper https://github.com/ruby/ruby/blob/trunk/ext/ripper/lib/ripper/lexer.rb#L166 def on_heredoc_dedent(v, w) ignored_sp = [] heredoc = @buf.last - heredoc.each_with_index do |e, i| - if Elem === e and e.event == :on_tstring_content and e.pos[1].zero? - tok = e.tok.dup if w > 0 and /\A\s/ =~ e.tok - if (n = dedent_string(e.tok, w)) > 0 - if e.tok.empty? - e.tok = tok[0, n] - e.event = :on_ignored_sp - next + if Array === heredoc + heredoc.each_with_index do |e, i| + if Elem === e and e.event == :on_tstring_content and e.pos[1].zero? + tok = e.tok.dup if w > 0 and /\A\s/ =~ e.tok + if (n = dedent_string(e.tok, w)) > 0 + if e.tok.empty? + e.tok = tok[0, n] + e.event = :on_ignored_sp + next + end + ignored_sp << [i, Elem.new(e.pos.dup, :on_ignored_sp, tok[0, n], e.state)] + e.pos[1] += n end - ignored_sp << [i, Elem.new(e.pos.dup, :on_ignored_sp, tok[0, n], e.state)] - e.pos[1] += n end end end -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/