[前][次][番号順一覧][スレッド一覧]

ruby-changes:66611

From: Masataka <ko1@a...>
Date: Sun, 27 Jun 2021 10:36:26 +0900 (JST)
Subject: [ruby-changes:66611] 6eb7c663c6 (master): [ruby/irb] Improve performance of `show_source` for large class

https://git.ruby-lang.org/ruby.git/commit/?id=6eb7c663c6

From 6eb7c663c665c633bdeae185d45e78832e672acc Mon Sep 17 00:00:00 2001
From: Masataka Pocke Kuwabara <kuwabara@p...>
Date: Fri, 25 Jun 2021 14:29:28 +0900
Subject: [ruby/irb] Improve performance of `show_source` for large class

https://github.com/ruby/irb/commit/2b79e9ad21
---
 lib/irb/cmd/show_source.rb | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/lib/irb/cmd/show_source.rb b/lib/irb/cmd/show_source.rb
index 0bd40b7..dcba1d1 100644
--- a/lib/irb/cmd/show_source.rb
+++ b/lib/irb/cmd/show_source.rb
@@ -59,11 +59,18 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/cmd/show_source.rb#L59
       def find_end(file, first_line)
         return first_line unless File.exist?(file)
         lex = RubyLex.new
-        code = +""
-        File.read(file).lines[(first_line - 1)..-1].each_with_index do |line, i|
-          _ltype, _indent, continue, code_block_open = lex.check_state(code << line)
+        lines = File.read(file).lines[(first_line - 1)..-1]
+        tokens = RubyLex.ripper_lex_without_warning(lines.join)
+        prev_tokens = []
+
+        # chunk with line number
+        tokens.chunk { |tok| tok[0][0] }.each do |lnum, chunk|
+          code = lines[0..lnum].join
+          prev_tokens.concat chunk
+          continue = lex.process_continue(prev_tokens)
+          code_block_open = lex.check_code_block(code, prev_tokens)
           if !continue && !code_block_open
-            return first_line + i
+            return first_line + lnum
           end
         end
         first_line
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]