From 0735ff9605fbe540f88c90a0b3fbc27a9b15d5ad Mon Sep 17 00:00:00 2001 From: uwetews Date: Sun, 14 Feb 2016 20:57:21 +0100 Subject: [PATCH] - optimization make compiler tag object cache static for higher compilation speed --- change_log.txt | 1 + libs/Smarty.class.php | 2 +- ...y_internal_compile_private_special_variable.php | 6 +++--- libs/sysplugins/smarty_internal_compilebase.php | 10 ++++++++++ .../smarty_internal_templatecompilerbase.php | 14 +++++++------- 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/change_log.txt b/change_log.txt index c338830c..0cd63aa5 100644 --- a/change_log.txt +++ b/change_log.txt @@ -4,6 +4,7 @@ - optimization of sub-template processing - bugfix using extendsall as default resource and {include} inside {block} tags could produce unexpected results https://github.com/smarty-php/smarty/issues/183 - optimization of tag attribute compiling + - optimization make compiler tag object cache static for higher compilation speed 11.02.2016 - improvement added KnockoutJS comments to trimwhitespace outputfilter https://github.com/smarty-php/smarty/issues/82 diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 338fbf42..2c5ef21b 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -121,7 +121,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.30-dev/42'; + const SMARTY_VERSION = '3.1.30-dev/44'; /** * define variable scopes diff --git a/libs/sysplugins/smarty_internal_compile_private_special_variable.php b/libs/sysplugins/smarty_internal_compile_private_special_variable.php index bb0de054..0c6be44f 100644 --- a/libs/sysplugins/smarty_internal_compile_private_special_variable.php +++ b/libs/sysplugins/smarty_internal_compile_private_special_variable.php @@ -39,11 +39,11 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C switch ($variable) { case 'foreach': case 'section': - if (!isset($compiler->_tag_objects[ $variable ])) { + if (!isset(Smarty_Internal_TemplateCompilerBase::$_tag_objects[ $variable ])) { $class = 'Smarty_Internal_Compile_' . ucfirst($variable); - $compiler->_tag_objects[ $variable ] = new $class; + Smarty_Internal_TemplateCompilerBase::$_tag_objects[ $variable ] = new $class; } - return $compiler->_tag_objects[ $variable ]->compileSpecialVariable(array(), $compiler, $_index); + return Smarty_Internal_TemplateCompilerBase::$_tag_objects[ $variable ]->compileSpecialVariable(array(), $compiler, $_index); case 'capture': if (class_exists('Smarty_Internal_Compile_Capture')) { return Smarty_Internal_Compile_Capture::compileSpecialVariable(array(), $compiler, $_index); diff --git a/libs/sysplugins/smarty_internal_compilebase.php b/libs/sysplugins/smarty_internal_compilebase.php index 390e669e..08aab6f4 100644 --- a/libs/sysplugins/smarty_internal_compilebase.php +++ b/libs/sysplugins/smarty_internal_compilebase.php @@ -44,8 +44,18 @@ abstract class Smarty_Internal_CompileBase */ public $option_flags = array('nocache'); + /** + * Mapping array for boolqn option value + * + * @var array + */ public $optionMap = array(1 => true, 0 => false, 'true' => true, 'false' => false); + /** + * Mapping array with attributes as key + * + * @var array + */ public $mapCache = array(); /** diff --git a/libs/sysplugins/smarty_internal_templatecompilerbase.php b/libs/sysplugins/smarty_internal_templatecompilerbase.php index 778e2be9..a091d90b 100644 --- a/libs/sysplugins/smarty_internal_templatecompilerbase.php +++ b/libs/sysplugins/smarty_internal_templatecompilerbase.php @@ -56,7 +56,7 @@ abstract class Smarty_Internal_TemplateCompilerBase * * @var array */ - public $_tag_objects = array(); + static $_tag_objects = array(); /** * tag stack @@ -403,7 +403,7 @@ abstract class Smarty_Internal_TemplateCompilerBase $this->smarty->_debug->end_compile($this->template); } $this->_tag_stack = array(); - $this->_tag_objects = array(); + self::$_tag_objects = array(); // free memory $this->parent_compiler = null; $this->template = null; @@ -867,7 +867,7 @@ abstract class Smarty_Internal_TemplateCompilerBase public function callTagCompiler($tag, $args, $param1 = null, $param2 = null, $param3 = null) { // re-use object if already exists - if (!isset($this->_tag_objects[ $tag ])) { + if (!isset(self::$_tag_objects[ $tag ])) { // lazy load internal compiler plugin $_tag = explode('_', $tag); $_tag = array_map('ucfirst', $_tag); @@ -875,15 +875,15 @@ abstract class Smarty_Internal_TemplateCompilerBase if (class_exists($class_name) && (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this)) ) { - $this->_tag_objects[ $tag ] = new $class_name; + self::$_tag_objects[ $tag ] = new $class_name; } else { - $this->_tag_objects[ $tag ] = false; + self::$_tag_objects[ $tag ] = false; return false; } } // compile this tag - return $this->_tag_objects[ $tag ] === false ? false : - $this->_tag_objects[ $tag ]->compile($args, $this, $param1, $param2, $param3); + return self::$_tag_objects[ $tag ] === false ? false : + self::$_tag_objects[ $tag ]->compile($args, $this, $param1, $param2, $param3); } /**