diff --git a/change_log.txt b/change_log.txt index f5433865..c20f4217 100644 --- a/change_log.txt +++ b/change_log.txt @@ -12,6 +12,7 @@ - remove properties with redundant content - optimize Smarty::templateExists() - optimize use_include_path processing + - relocate properties for size optimization 06.08.2015 - avoid possible circular object references caused by parser/lexer objects diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 346bc993..e9737a7c 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -486,13 +486,6 @@ class Smarty extends Smarty_Internal_TemplateBase */ public $error_reporting = null; - /** - * Internal flag for getTags() - * - * @var boolean - */ - public $get_used_tags = false; - /**#@+ * config var settings */ @@ -654,13 +647,6 @@ class Smarty extends Smarty_Internal_TemplateBase */ public $start_time = 0; - /** - * block tag hierarchy - * - * @var array - */ - public $_tag_stack = array(); - /** * required by the compiler for BC * diff --git a/libs/sysplugins/smarty_internal_compile_block.php b/libs/sysplugins/smarty_internal_compile_block.php index 92724100..1d97ac81 100644 --- a/libs/sysplugins/smarty_internal_compile_block.php +++ b/libs/sysplugins/smarty_internal_compile_block.php @@ -163,11 +163,11 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase $compiler->smarty->_debug->ignore($_tpl); } $_tpl->tpl_vars = $compiler->template->tpl_vars; - $_tpl->variable_filters = $compiler->template->variable_filters; $_tpl->compiled = new Smarty_Template_Compiled(); $_tpl->compiled->nocache_hash = $compiler->template->compiled->nocache_hash; - $_tpl->allow_relative_path = true; + $_tpl->_cache['allow_relative_path'] = true; $_tpl->loadCompiler(); + $_tpl->compiler->variable_filters = $compiler->variable_filters; $_tpl->compiler->parent_compiler = $compiler; $_tpl->compiler->_tag_objects = $compiler->_tag_objects; $_tpl->compiler->inheritance = true; @@ -190,7 +190,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase $compiler->template->compiled->file_dependency = array_merge($compiler->template->compiled->file_dependency, $_tpl->compiled->file_dependency); unset($compiler->template->compiled->file_dependency[$_tpl->source->uid]); $compiler->template->tpl_function = array_merge($compiler->template->tpl_function, $_tpl->tpl_function); - $compiler->template->variable_filters = $_tpl->variable_filters; + $compiler->variable_filters = $_tpl->compiler->variable_filters; if ($_tpl->compiled->has_nocache_code) { $compiler->template->compiled->has_nocache_code = true; } diff --git a/libs/sysplugins/smarty_internal_compile_capture.php b/libs/sysplugins/smarty_internal_compile_capture.php index 873ca79e..95c75a4b 100644 --- a/libs/sysplugins/smarty_internal_compile_capture.php +++ b/libs/sysplugins/smarty_internal_compile_capture.php @@ -52,7 +52,7 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase $compiler->_capture_stack[0][] = array($buffer, $assign, $append, $compiler->nocache); // maybe nocache because of nocache variables $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; - $_output = "_capture_stack[0][] = array($buffer, $assign, $append); ob_start(); ?>"; + $_output = "_cache['capture_stack'][] = array($buffer, $assign, $append); ob_start(); ?>"; return $_output; } @@ -106,7 +106,7 @@ class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase list($buffer, $assign, $append, $compiler->nocache) = array_pop($compiler->_capture_stack[0]); - $_output = "_capture_stack[0]);\n"; + $_output = "_cache['capture_stack']);\n"; $_output .= "if (!empty(\$_capture_buffer)) {\n"; $_output .= " if (isset(\$_capture_assign)) \$_smarty_tpl->assign(\$_capture_assign, ob_get_contents());\n"; $_output .= " if (isset( \$_capture_append)) \$_smarty_tpl->append( \$_capture_append, ob_get_contents());\n"; diff --git a/libs/sysplugins/smarty_internal_compile_private_block_plugin.php b/libs/sysplugins/smarty_internal_compile_private_block_plugin.php index f0d23e2a..9e2eea23 100644 --- a/libs/sysplugins/smarty_internal_compile_private_block_plugin.php +++ b/libs/sysplugins/smarty_internal_compile_private_block_plugin.php @@ -60,7 +60,7 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi // maybe nocache because of nocache variables or nocache plugin $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; // compile code - $output = "smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; + $output = "smarty->_cache['tag_stack'][] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; } else { // must endblock be nocache? if ($compiler->nocache) { @@ -81,7 +81,7 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi } $output = "smarty->_tag_stack);?>"; + " } array_pop(\$_smarty_tpl->smarty->_cache['tag_stack']);?>"; } return $output . "\n"; diff --git a/libs/sysplugins/smarty_internal_compile_private_object_block_function.php b/libs/sysplugins/smarty_internal_compile_private_object_block_function.php index 46eb27d5..c6cf488d 100644 --- a/libs/sysplugins/smarty_internal_compile_private_object_block_function.php +++ b/libs/sysplugins/smarty_internal_compile_private_object_block_function.php @@ -60,7 +60,7 @@ class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Inter // maybe nocache because of nocache variables or nocache plugin $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; // compile code - $output = "smarty->_tag_stack[] = array('{$tag}->{$method}', {$_params}); \$_block_repeat=true; echo \$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; + $output = "smarty->_cache['tag_stack'][] = array('{$tag}->{$method}', {$_params}); \$_block_repeat=true; echo \$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; } else { $base_tag = substr($tag, 0, - 5); // must endblock be nocache? @@ -82,7 +82,7 @@ class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Inter } $output = "smarty->registered_objects['{$base_tag}'][0]->{$method}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . - $mod_post . " } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; + $mod_post . " } array_pop(\$_smarty_tpl->smarty->_cache['tag_stack']);?>"; } return $output . "\n"; diff --git a/libs/sysplugins/smarty_internal_compile_private_print_expression.php b/libs/sysplugins/smarty_internal_compile_private_print_expression.php index af714a53..c0c089bf 100644 --- a/libs/sysplugins/smarty_internal_compile_private_print_expression.php +++ b/libs/sysplugins/smarty_internal_compile_private_print_expression.php @@ -108,16 +108,14 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C } } } - if (isset($compiler->template->variable_filters)) { - foreach ($compiler->template->variable_filters as $filter) { - if (count($filter) == 1 && - ($result = $this->compile_output_filter($compiler, $filter[0], $output)) !== false - ) { - $output = $result; - } else { - $output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => array($filter), - 'value' => $output)); - } + foreach ($compiler->variable_filters as $filter) { + if (count($filter) == 1 && + ($result = $this->compile_output_filter($compiler, $filter[0], $output)) !== false + ) { + $output = $result; + } else { + $output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => array($filter), + 'value' => $output)); } } } diff --git a/libs/sysplugins/smarty_internal_compile_private_registered_block.php b/libs/sysplugins/smarty_internal_compile_private_registered_block.php index 640eb34e..78d95f72 100644 --- a/libs/sysplugins/smarty_internal_compile_private_registered_block.php +++ b/libs/sysplugins/smarty_internal_compile_private_registered_block.php @@ -69,11 +69,11 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C $function = $tag_info[0]; // compile code if (!is_array($function)) { - $output = "smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; + $output = "smarty->_cache['tag_stack'][] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; } elseif (is_object($function[0])) { - $output = "smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo \$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0][0]->{$function[1]}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; + $output = "smarty->_cache['tag_stack'][] = array('{$tag}', {$_params}); \$_block_repeat=true; echo \$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0][0]->{$function[1]}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; } else { - $output = "smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function[0]}::{$function[1]}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; + $output = "smarty->_cache['tag_stack'][] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function[0]}::{$function[1]}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; } } else { // must endblock be nocache? @@ -102,15 +102,15 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C if (!is_array($function)) { $output = "smarty->_tag_stack);?>"; + " } array_pop(\$_smarty_tpl->smarty->_cache['tag_stack']);?>"; } elseif (is_object($function[0])) { $output = "smarty->registered_plugins['block']['{$base_tag}'][0][0]->{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . - $mod_post . "} array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; + $mod_post . "} array_pop(\$_smarty_tpl->smarty->_cache['tag_stack']);?>"; } else { $output = "smarty->_tag_stack);?>"; + $mod_post . "} array_pop(\$_smarty_tpl->smarty->_cache['tag_stack']);?>"; } } diff --git a/libs/sysplugins/smarty_internal_compile_setfilter.php b/libs/sysplugins/smarty_internal_compile_setfilter.php index 0f70ab62..b4932c1e 100644 --- a/libs/sysplugins/smarty_internal_compile_setfilter.php +++ b/libs/sysplugins/smarty_internal_compile_setfilter.php @@ -27,8 +27,8 @@ class Smarty_Internal_Compile_Setfilter extends Smarty_Internal_CompileBase */ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) { - $compiler->variable_filter_stack[] = $compiler->template->variable_filters; - $compiler->template->variable_filters = $parameter['modifier_list']; + $compiler->variable_filter_stack[] = $compiler->variable_filters; + $compiler->variable_filters = $parameter['modifier_list']; // this tag does not return compiled code $compiler->has_code = false; @@ -58,9 +58,9 @@ class Smarty_Internal_Compile_Setfilterclose extends Smarty_Internal_CompileBase $_attr = $this->getAttributes($compiler, $args); // reset variable filter to previous state if (count($compiler->variable_filter_stack)) { - $compiler->template->variable_filters = array_pop($compiler->variable_filter_stack); + $compiler->variable_filters = array_pop($compiler->variable_filter_stack); } else { - $compiler->template->variable_filters = array(); + $compiler->variable_filters = array(); } // this tag does not return compiled code $compiler->has_code = false; diff --git a/libs/sysplugins/smarty_internal_method_gettags.php b/libs/sysplugins/smarty_internal_method_gettags.php index 3a96b508..dd9e8d1c 100644 --- a/libs/sysplugins/smarty_internal_method_gettags.php +++ b/libs/sysplugins/smarty_internal_method_gettags.php @@ -48,13 +48,14 @@ class Smarty_Internal_Method_GetTags } if (isset($tpl)) { $tpl->smarty = clone $tpl->smarty; - $tpl->smarty->get_used_tags = true; + $tpl->smarty->_cache['get_used_tags'] = true; + $tpl->_cache['used_tags'] = array(); $tpl->smarty->merge_compiled_includes = false; $tpl->smarty->disableSecurity(); $tpl->caching = false; $tpl->loadCompiler(); $tpl->compiler->compileTemplate($tpl); - return $tpl->used_tags; + return $tpl->_cache['used_tags']; } throw new SmartyException("Missing template specification"); } diff --git a/libs/sysplugins/smarty_internal_resource_file.php b/libs/sysplugins/smarty_internal_resource_file.php index 47736892..c9d63263 100644 --- a/libs/sysplugins/smarty_internal_resource_file.php +++ b/libs/sysplugins/smarty_internal_resource_file.php @@ -39,7 +39,7 @@ class Smarty_Internal_Resource_File extends Smarty_Resource preg_match('#^[.]{1,2}[\\\/]#', $file) ) { if ($_template->parent->source->type != 'file' && $_template->parent->source->type != 'extends' && - !$_template->parent->allow_relative_path + !isset($_template->parent->_cache['allow_relative_path']) ) { throw new SmartyException("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'"); } diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index 485be1a4..1e4fdf16 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -63,34 +63,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase */ public $block_data = array(); - /** - * variable filters - * - * @var array - */ - public $variable_filters = array(); - - /** - * optional log of tag/attributes - * - * @var array - */ - public $used_tags = array(); - - /** - * internal flag to allow relative path in child template blocks - * - * @var bool - */ - public $allow_relative_path = false; - - /** - * internal capture runtime stack - * - * @var array - */ - public $_capture_stack = array(0 => array()); - /** * Template Id * @@ -302,16 +274,14 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase if (isset($this->smarty->security_policy)) { $this->smarty->security_policy->startTemplate($this); } - array_unshift($this->_capture_stack, array()); - // + // // render compiled or saved template code // $unifunc($this); // any unclosed {capture} tags ? - if (isset($this->_capture_stack[0][0])) { + if (isset($this->_cache['capture_stack'][0])) { $this->capture_error(); } - array_shift($this->_capture_stack); if (isset($this->smarty->security_policy)) { $this->smarty->security_policy->exitTemplate(); } @@ -321,7 +291,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase while (ob_get_level() > $level) { ob_end_clean(); } - array_shift($this->_capture_stack); if (isset($this->smarty->security_policy)) { $this->smarty->security_policy->exitTemplate(); } diff --git a/libs/sysplugins/smarty_internal_templatecompilerbase.php b/libs/sysplugins/smarty_internal_templatecompilerbase.php index 28aea607..97a1280a 100644 --- a/libs/sysplugins/smarty_internal_templatecompilerbase.php +++ b/libs/sysplugins/smarty_internal_templatecompilerbase.php @@ -320,6 +320,13 @@ abstract class Smarty_Internal_TemplateCompilerBase public $variable_filter_stack = array(); /** + * variable filters for {setfilter} {/setfilter} + * + * @var array + */ + public $variable_filters = array(); + + /** * Loop nesting count * * @var int @@ -545,8 +552,8 @@ abstract class Smarty_Internal_TemplateCompilerBase $this->has_code = true; $this->has_output = false; // log tag/attributes - if (isset($this->smarty->get_used_tags) && $this->smarty->get_used_tags) { - $this->template->used_tags[] = array($tag, $args); + if (isset($this->smarty->_cache['get_used_tags'])) { + $this->template->_cache['used_tags'][] = array($tag, $args); } // check nocache option flag if (in_array("'nocache'", $args) || in_array(array('nocache' => 'true'), $args) || diff --git a/libs/sysplugins/smarty_template_resource_base.php b/libs/sysplugins/smarty_template_resource_base.php index 19d5d536..2f7ef194 100644 --- a/libs/sysplugins/smarty_template_resource_base.php +++ b/libs/sysplugins/smarty_template_resource_base.php @@ -119,16 +119,14 @@ abstract class Smarty_Template_Resource_Base if (isset($_template->smarty->security_policy)) { $_template->smarty->security_policy->startTemplate($_template); } - array_unshift($_template->_capture_stack, array()); // // render compiled or saved template code // $unifunc($_template); // any unclosed {capture} tags ? - if (isset($_template->_capture_stack[0][0])) { + if (isset($_template->_cache['capture_stack'][0])) { $_template->capture_error(); } - array_shift($_template->_capture_stack); if (isset($_template->smarty->security_policy)) { $_template->smarty->security_policy->exitTemplate(); } @@ -138,8 +136,7 @@ abstract class Smarty_Template_Resource_Base while (ob_get_level() > $level) { ob_end_clean(); } - array_shift($_template->_capture_stack); - if (isset($_template->smarty->security_policy)) { + if (isset($_template->smarty->security_policy)) { $_template->smarty->security_policy->exitTemplate(); } throw $e;