Separate RDoc::TokenStream#add_tokens and #add_token
The old version of `add_tokens` accepts an array of tokens, and multiple arguments of tokens by using `Array#flatten`. And `add_token` was an alias to `add_tokens`. I think it is unnecessarily flexible; in fact, all callsites of `add_tokens` (except test) passes only an array of tokens. And the code created a lot of temporal arrays. This change makes `add_tokens` accept only one array of tokens, and does `add_token` accept one token. It is a bit faster (about 1 second in Ruby's `make rdoc`), and it ls also cleaner in my point of view.
This commit is contained in:
parent
0a0760aa63
commit
723a37d038
@ -74,11 +74,16 @@ module RDoc::TokenStream
|
|||||||
##
|
##
|
||||||
# Adds +tokens+ to the collected tokens
|
# Adds +tokens+ to the collected tokens
|
||||||
|
|
||||||
def add_tokens(*tokens)
|
def add_tokens(tokens)
|
||||||
tokens.flatten.each { |token| @token_stream << token }
|
@token_stream.concat(tokens)
|
||||||
end
|
end
|
||||||
|
|
||||||
alias add_token add_tokens
|
##
|
||||||
|
# Adds one +token+ to the collected tokens
|
||||||
|
|
||||||
|
def add_token(token)
|
||||||
|
@token_stream.push(token)
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Starts collecting tokens
|
# Starts collecting tokens
|
||||||
|
@ -78,7 +78,7 @@ method(a, b) { |c, d| ... }
|
|||||||
]
|
]
|
||||||
|
|
||||||
@c2_a.collect_tokens
|
@c2_a.collect_tokens
|
||||||
@c2_a.add_tokens(*tokens)
|
@c2_a.add_tokens(tokens)
|
||||||
|
|
||||||
expected = '<span class="ruby-constant">CONSTANT</span>'
|
expected = '<span class="ruby-constant">CONSTANT</span>'
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ method(a, b) { |c, d| ... }
|
|||||||
]
|
]
|
||||||
|
|
||||||
@c2_a.collect_tokens
|
@c2_a.collect_tokens
|
||||||
@c2_a.add_tokens(*tokens)
|
@c2_a.add_tokens(tokens)
|
||||||
|
|
||||||
assert_equal <<-EXPECTED.chomp, @c2_a.markup_code
|
assert_equal <<-EXPECTED.chomp, @c2_a.markup_code
|
||||||
<span class="ruby-comment"># File xref_data.rb, line 1</span>
|
<span class="ruby-comment"># File xref_data.rb, line 1</span>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user