Don't use define_method in the lexer.

Profiling showed that calls to methods defined using `define_method` are
really, really slow. Before this commit the lexer would process 3000-4000
lines per second. With this commit that has been increased to around 10 000
lines per second.

Thanks to @headius for mentioning the (potential) overhead of define_method.
This commit is contained in:
Yorick Peterse 2014-04-17 19:08:26 +02:00
parent d9fa4b7c45
commit 54e6650338
1 changed files with 10 additions and 10 deletions

View File

@ -47,16 +47,6 @@ module Oga
'wbr' 'wbr'
]) ])
# Lazy way of forwarding instance method calls used internally by Ragel
# to their corresponding class methods.
private_methods.grep(/^_lexer_/).each do |name|
define_method(name) do
return self.class.send(name)
end
private(name)
end
## ##
# @param [String] data The data to lex. # @param [String] data The data to lex.
# #
@ -141,6 +131,16 @@ module Oga
def advance(&block) def advance(&block)
@block = block @block = block
_lexer_eof_trans = self.class.send(:_lexer_eof_trans)
_lexer_from_state_actions = self.class.send(:_lexer_from_state_actions)
_lexer_index_offsets = self.class.send(:_lexer_index_offsets)
_lexer_indicies = self.class.send(:_lexer_indicies)
_lexer_key_spans = self.class.send(:_lexer_key_spans)
_lexer_to_state_actions = self.class.send(:_lexer_to_state_actions)
_lexer_trans_actions = self.class.send(:_lexer_trans_actions)
_lexer_trans_keys = self.class.send(:_lexer_trans_keys)
_lexer_trans_targs = self.class.send(:_lexer_trans_targs)
%% write exec; %% write exec;
# % fix highlight # % fix highlight