Skip to content

Commit

Permalink
Remove an extra branch from the bottleneck
Browse files Browse the repository at this point in the history
RDoc::RubyLex#getc is the bottleneck in RDoc.  It determined which
ungetc buffer to use by branching upon `@here_header`.  We can remove
the branch by replacing `@here_header` flag with `@current_readed`,
which represents the current buffer directly,
  • Loading branch information
mame committed Mar 15, 2016
1 parent 869202f commit 72f14d8
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions lib/rdoc/ruby_lex.rb
Expand Up @@ -101,10 +101,10 @@ def initialize(content, options)
@exp_line_no = @line_no = 1
@here_readed = []
@readed = []
@current_readed = @readed
@rests = []
@seek = 0

@here_header = false
@indent = 0
@indent_stack = []
@lex_state = :EXPR_BEG
Expand Down Expand Up @@ -160,7 +160,7 @@ def get_readed
end

readed = @readed.join("")
@readed = []
@readed.clear
readed
end

Expand All @@ -170,13 +170,9 @@ def getc
@rests.push nil unless buf_input
end
c = @rests.shift
if @here_header
@here_readed.push c
else
@readed.push c
end
@current_readed.push c
@seek += 1
if c == "\n"
if c == "\n".freeze
@line_no += 1
@char_no = 0
else
Expand Down Expand Up @@ -282,7 +278,7 @@ def initialize_input
@indent_stack = []
@lex_state = :EXPR_BEG
@space_seen = false
@here_header = false
@current_readed = @readed

@continue = false
prompt
Expand Down Expand Up @@ -461,8 +457,8 @@ def lex_init()
@indent_stack.pop
end
end
@here_header = false
@here_readed = []
@current_readed = @readed
@here_readed.clear
Token(TkNL)
end

Expand Down Expand Up @@ -1020,7 +1016,7 @@ def identify_here_document
doc = '"'
end

@here_header = false
@current_readed = @readed
while l = gets
l = l.sub(/(:?\r)?\n\z/, "\n")
if (indent ? l.strip : l.chomp) == quoted
Expand All @@ -1037,7 +1033,7 @@ def identify_here_document
doc << '"'
end

@here_header = true
@current_readed = @here_readed
@here_readed.concat reserve
while ch = reserve.pop
ungetc ch
Expand Down

0 comments on commit 72f14d8

Please sign in to comment.