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

View File

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