No need to loop through pragma tokens twice.
Add them directly to the token list as soon as they are tokenized.
This commit is contained in:
+12
-12
@@ -70,7 +70,6 @@ class Mustache_Tokenizer
|
|||||||
const NODES = 'nodes';
|
const NODES = 'nodes';
|
||||||
const VALUE = 'value';
|
const VALUE = 'value';
|
||||||
|
|
||||||
private $pragmas;
|
|
||||||
private $state;
|
private $state;
|
||||||
private $tagType;
|
private $tagType;
|
||||||
private $tag;
|
private $tag;
|
||||||
@@ -177,14 +176,6 @@ class Mustache_Tokenizer
|
|||||||
|
|
||||||
$this->flushBuffer();
|
$this->flushBuffer();
|
||||||
|
|
||||||
// Pragmas are hoisted to the front of the template.
|
|
||||||
foreach ($this->pragmas as $pragma) {
|
|
||||||
array_unshift($this->tokens, array(
|
|
||||||
self::TYPE => self::T_PRAGMA,
|
|
||||||
self::NAME => $pragma,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->tokens;
|
return $this->tokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,7 +193,6 @@ class Mustache_Tokenizer
|
|||||||
$this->line = 0;
|
$this->line = 0;
|
||||||
$this->otag = '{{';
|
$this->otag = '{{';
|
||||||
$this->ctag = '}}';
|
$this->ctag = '}}';
|
||||||
$this->pragmas = array();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -242,7 +232,10 @@ class Mustache_Tokenizer
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add pragma tag this template's list of pragmas.
|
* Add pragma token.
|
||||||
|
*
|
||||||
|
* Pragmas are hoisted to the front of the template, so all pragma tokens
|
||||||
|
* will appear at the front of the token list.
|
||||||
*
|
*
|
||||||
* @param string $text
|
* @param string $text
|
||||||
* @param int $index
|
* @param int $index
|
||||||
@@ -252,7 +245,14 @@ class Mustache_Tokenizer
|
|||||||
private function addPragma($text, $index)
|
private function addPragma($text, $index)
|
||||||
{
|
{
|
||||||
$end = strpos($text, $this->ctag, $index);
|
$end = strpos($text, $this->ctag, $index);
|
||||||
$this->pragmas[] = trim(substr($text, $index + 2, $end - $index - 2));
|
$pragma = trim(substr($text, $index + 2, $end - $index - 2));
|
||||||
|
|
||||||
|
// Pragmas are hoisted to the front of the template.
|
||||||
|
array_unshift($this->tokens, array(
|
||||||
|
self::TYPE => self::T_PRAGMA,
|
||||||
|
self::NAME => $pragma,
|
||||||
|
self::LINE => 0,
|
||||||
|
));
|
||||||
|
|
||||||
return $end + strlen($this->ctag) - 1;
|
return $end + strlen($this->ctag) - 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user