]> git.wincent.com - walrat.git/commit
Call to_parseable before storing rules
authorWincent Colaiuta <win@wincent.com>
Fri, 27 Aug 2010 16:17:14 +0000 (18:17 +0200)
committerWincent Colaiuta <win@wincent.com>
Fri, 27 Aug 2010 16:17:14 +0000 (18:17 +0200)
commit22de98cb1513927420a3484a5da856f00537253b
treed0d864ae7b85f4b966936790fc905e317026d5cd
parent9dbab08db3a43b37c4faf8531eee36f738c8ffb0
Call to_parseable before storing rules

Given a rule like:

  rule :foo, 'bar'

We previously stored the string literal in the rules hash. At parse
time, these rules get accessed via the SymbolParslet class, which
does:

  result = grammar.rules[@symbol].memoizing_parse(...)

The memoizing_parse method itself calls to_parseable on the rule,
which means that every time we evaluate a rule like :foo we end up
creating a new StringParslet instance.

By storing 'bar'.to_parseable in the rules hash instead we avoid
the unnecessary object creation. With this change each time
memoizing_parse calls to_parseable on the stored value, the same
instance is returned and no new object is created, thus reducing memory
use.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
lib/walrat/grammar.rb