Don't create Arrays when not needed.
This commit is contained in:
parent
854936f30b
commit
81a81f0ab0
|
@ -77,8 +77,8 @@ module Oga
|
|||
def lex
|
||||
tokens = []
|
||||
|
||||
advance do |token|
|
||||
tokens << token
|
||||
advance do |type, value, line|
|
||||
tokens << [type, value, line]
|
||||
end
|
||||
|
||||
reset
|
||||
|
@ -130,15 +130,17 @@ module Oga
|
|||
end
|
||||
|
||||
##
|
||||
# Adds a token with the given type and value to the list.
|
||||
# Calls the supplied block with the information of the current token.
|
||||
#
|
||||
# @param [Symbol] type The token type.
|
||||
# @param [String] value The token value.
|
||||
#
|
||||
# @yieldparam [String] type
|
||||
# @yieldparam [String] value
|
||||
# @yieldparam [Fixnum] line
|
||||
#
|
||||
def add_token(type, value = nil)
|
||||
token = [type, value, @line]
|
||||
|
||||
@block.call(token)
|
||||
@block.call(type, value, @line)
|
||||
end
|
||||
|
||||
##
|
||||
|
|
|
@ -184,7 +184,7 @@ end
|
|||
# @yieldparam [Array]
|
||||
#
|
||||
def yield_next_token
|
||||
@lexer.advance do |(type, value, line)|
|
||||
@lexer.advance do |type, value, line|
|
||||
@line = line if line
|
||||
|
||||
yield [type, value]
|
||||
|
|
Loading…
Reference in New Issue