diff options
| author | uwetews <uwe.tews@googlemail.com> | 2016-11-07 03:08:11 +0100 |
|---|---|---|
| committer | uwetews <uwe.tews@googlemail.com> | 2016-11-07 03:08:11 +0100 |
| commit | c4746e9080802a5fe794f7047c36ee79900431eb (patch) | |
| tree | 3114ef6be813666eae915213a84d8d8eada7e93b /lexer/smarty_internal_templatelexer.plex | |
| parent | 2d2be8f57ffdb5bbf567feaaf35dc4e7d0a42938 (diff) | |
| download | smarty-c4746e9080802a5fe794f7047c36ee79900431eb.tar.gz smarty-c4746e9080802a5fe794f7047c36ee79900431eb.tar.bz2 smarty-c4746e9080802a5fe794f7047c36ee79900431eb.zip | |
- optimization of lexer speed https://github.com/smarty-php/smarty/issues/311
Diffstat (limited to 'lexer/smarty_internal_templatelexer.plex')
| -rw-r--r-- | lexer/smarty_internal_templatelexer.plex | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/lexer/smarty_internal_templatelexer.plex b/lexer/smarty_internal_templatelexer.plex index a455baf8..bf0d97c7 100644 --- a/lexer/smarty_internal_templatelexer.plex +++ b/lexer/smarty_internal_templatelexer.plex @@ -26,6 +26,13 @@ class Smarty_Internal_Templatelexer public $data; /** + * Source length + * + * @var int + */ + public $dataLenght = null; + + /** * byte counter * * @var int @@ -225,6 +232,7 @@ class Smarty_Internal_Templatelexer function __construct($data, Smarty_Internal_TemplateCompilerBase $compiler) { $this->data = $data; + $this->dataLenght = strlen($data); $this->counter = 0; if (preg_match('/^\xEF\xBB\xBF/i', $this->data, $match)) { $this->counter += strlen($match[0]); @@ -366,7 +374,7 @@ class Smarty_Internal_Templatelexer $this->compiler->getTagCompiler('private_php')->parsePhp($this); } text { - $to = strlen($this->data); + $to = $this->dataLenght; preg_match("/($this->ldel)|(<[?]((php\s+|=)|\s+))|(<[%])|(<[?]xml\s+)|(<script\s+language\s*=\s*[\"']?\s*php\s*[\"']?\s*>)|([?][>])|([%][>])/i",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter); if (isset($match[0][1])) { $to = $match[0][1]; @@ -606,7 +614,7 @@ class Smarty_Internal_Templatelexer } } text { - $to = strlen($this->data); + $to = $this->dataLenght; preg_match("/{$this->ldel}[\/]?literal{$this->rdel}/i",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter); if (isset($match[0][1])) { $to = $match[0][1]; @@ -670,7 +678,7 @@ class Smarty_Internal_Templatelexer $this->token = Smarty_Internal_Templateparser::TP_TEXT; } text { - $to = strlen($this->data); + $to = $this->dataLenght; $this->value = substr($this->data,$this->counter,$to-$this->counter); $this->token = Smarty_Internal_Templateparser::TP_TEXT; } |
