1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/irb] Improve performance of show_source for large class

https://github.com/ruby/irb/commit/2b79e9ad21
This commit is contained in:
Masataka Pocke Kuwabara 2021-06-25 14:29:28 +09:00 committed by git
parent bf789af28a
commit 6eb7c663c6

View file

@ -59,11 +59,18 @@ module IRB
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