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