Use a raw array for Parser::buildTree

Improve memory usage by ~15% for very large templates.
This commit is contained in:
Justin Hileman
2013-05-11 22:32:42 -07:00
parent ade0b98761
commit 697f4ac26b
+6 -8
View File
@@ -26,7 +26,7 @@ class Mustache_Parser
*/
public function parse(array $tokens = array())
{
return $this->buildTree(new ArrayIterator($tokens));
return $this->buildTree($tokens);
}
/**
@@ -34,18 +34,17 @@ class Mustache_Parser
*
* @throws Mustache_Exception_SyntaxException when nesting errors or mismatched section tags are encountered.
*
* @param ArrayIterator $tokens Stream of Mustache tokens
* @param array &$tokens Set of Mustache tokens
* @param array $parent Parent token (default: null)
*
* @return array Mustache Token parse tree
*/
private function buildTree(ArrayIterator $tokens, array $parent = null)
private function buildTree(array &$tokens, array $parent = null)
{
$nodes = array();
do {
$token = $tokens->current();
$tokens->next();
while (!empty($tokens)) {
$token = array_shift($tokens);
if ($token === null) {
continue;
@@ -78,8 +77,7 @@ class Mustache_Parser
break;
}
}
} while ($tokens->valid());
};
if (isset($parent)) {
$msg = sprintf('Missing closing tag: %s', $parent[Mustache_Tokenizer::NAME]);