Don't create Arrays when not needed.

This commit is contained in:
Yorick Peterse 2014-05-16 17:05:42 +02:00
parent 854936f30b
commit 81a81f0ab0
2 changed files with 9 additions and 7 deletions

View File

@ -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
##

View File

@ -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]