- optimization make compiler tag object cache static for higher compilation speed

This commit is contained in:
uwetews
2016-02-14 20:57:21 +01:00
parent 30328d318c
commit 0735ff9605
5 changed files with 22 additions and 11 deletions

View File

@@ -4,6 +4,7 @@
- optimization of sub-template processing - 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 - 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 of tag attribute compiling
- optimization make compiler tag object cache static for higher compilation speed
11.02.2016 11.02.2016
- improvement added KnockoutJS comments to trimwhitespace outputfilter https://github.com/smarty-php/smarty/issues/82 - improvement added KnockoutJS comments to trimwhitespace outputfilter https://github.com/smarty-php/smarty/issues/82

View File

@@ -121,7 +121,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/** /**
* smarty version * smarty version
*/ */
const SMARTY_VERSION = '3.1.30-dev/42'; const SMARTY_VERSION = '3.1.30-dev/44';
/** /**
* define variable scopes * define variable scopes

View File

@@ -39,11 +39,11 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
switch ($variable) { switch ($variable) {
case 'foreach': case 'foreach':
case 'section': case 'section':
if (!isset($compiler->_tag_objects[ $variable ])) { if (!isset(Smarty_Internal_TemplateCompilerBase::$_tag_objects[ $variable ])) {
$class = 'Smarty_Internal_Compile_' . ucfirst($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': case 'capture':
if (class_exists('Smarty_Internal_Compile_Capture')) { if (class_exists('Smarty_Internal_Compile_Capture')) {
return Smarty_Internal_Compile_Capture::compileSpecialVariable(array(), $compiler, $_index); return Smarty_Internal_Compile_Capture::compileSpecialVariable(array(), $compiler, $_index);

View File

@@ -44,8 +44,18 @@ abstract class Smarty_Internal_CompileBase
*/ */
public $option_flags = array('nocache'); public $option_flags = array('nocache');
/**
* Mapping array for boolqn option value
*
* @var array
*/
public $optionMap = array(1 => true, 0 => false, 'true' => true, 'false' => false); public $optionMap = array(1 => true, 0 => false, 'true' => true, 'false' => false);
/**
* Mapping array with attributes as key
*
* @var array
*/
public $mapCache = array(); public $mapCache = array();
/** /**

View File

@@ -56,7 +56,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
* *
* @var array * @var array
*/ */
public $_tag_objects = array(); static $_tag_objects = array();
/** /**
* tag stack * tag stack
@@ -403,7 +403,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
$this->smarty->_debug->end_compile($this->template); $this->smarty->_debug->end_compile($this->template);
} }
$this->_tag_stack = array(); $this->_tag_stack = array();
$this->_tag_objects = array(); self::$_tag_objects = array();
// free memory // free memory
$this->parent_compiler = null; $this->parent_compiler = null;
$this->template = null; $this->template = null;
@@ -867,7 +867,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
public function callTagCompiler($tag, $args, $param1 = null, $param2 = null, $param3 = null) public function callTagCompiler($tag, $args, $param1 = null, $param2 = null, $param3 = null)
{ {
// re-use object if already exists // re-use object if already exists
if (!isset($this->_tag_objects[ $tag ])) { if (!isset(self::$_tag_objects[ $tag ])) {
// lazy load internal compiler plugin // lazy load internal compiler plugin
$_tag = explode('_', $tag); $_tag = explode('_', $tag);
$_tag = array_map('ucfirst', $_tag); $_tag = array_map('ucfirst', $_tag);
@@ -875,15 +875,15 @@ abstract class Smarty_Internal_TemplateCompilerBase
if (class_exists($class_name) && if (class_exists($class_name) &&
(!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this)) (!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 { } else {
$this->_tag_objects[ $tag ] = false; self::$_tag_objects[ $tag ] = false;
return false; return false;
} }
} }
// compile this tag // compile this tag
return $this->_tag_objects[ $tag ] === false ? false : return self::$_tag_objects[ $tag ] === false ? false :
$this->_tag_objects[ $tag ]->compile($args, $this, $param1, $param2, $param3); self::$_tag_objects[ $tag ]->compile($args, $this, $param1, $param2, $param3);
} }
/** /**