- relocate properties for size optimization

This commit is contained in:
uwetews
2015-08-23 13:24:24 +02:00
parent 606b8e8669
commit 9eb87ef5a2
14 changed files with 45 additions and 86 deletions

View File

@@ -12,6 +12,7 @@
- remove properties with redundant content - remove properties with redundant content
- optimize Smarty::templateExists() - optimize Smarty::templateExists()
- optimize use_include_path processing - optimize use_include_path processing
- relocate properties for size optimization
06.08.2015 06.08.2015
- avoid possible circular object references caused by parser/lexer objects - avoid possible circular object references caused by parser/lexer objects

View File

@@ -486,13 +486,6 @@ class Smarty extends Smarty_Internal_TemplateBase
*/ */
public $error_reporting = null; public $error_reporting = null;
/**
* Internal flag for getTags()
*
* @var boolean
*/
public $get_used_tags = false;
/**#@+ /**#@+
* config var settings * config var settings
*/ */
@@ -654,13 +647,6 @@ class Smarty extends Smarty_Internal_TemplateBase
*/ */
public $start_time = 0; public $start_time = 0;
/**
* block tag hierarchy
*
* @var array
*/
public $_tag_stack = array();
/** /**
* required by the compiler for BC * required by the compiler for BC
* *

View File

@@ -163,11 +163,11 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
$compiler->smarty->_debug->ignore($_tpl); $compiler->smarty->_debug->ignore($_tpl);
} }
$_tpl->tpl_vars = $compiler->template->tpl_vars; $_tpl->tpl_vars = $compiler->template->tpl_vars;
$_tpl->variable_filters = $compiler->template->variable_filters;
$_tpl->compiled = new Smarty_Template_Compiled(); $_tpl->compiled = new Smarty_Template_Compiled();
$_tpl->compiled->nocache_hash = $compiler->template->compiled->nocache_hash; $_tpl->compiled->nocache_hash = $compiler->template->compiled->nocache_hash;
$_tpl->allow_relative_path = true; $_tpl->_cache['allow_relative_path'] = true;
$_tpl->loadCompiler(); $_tpl->loadCompiler();
$_tpl->compiler->variable_filters = $compiler->variable_filters;
$_tpl->compiler->parent_compiler = $compiler; $_tpl->compiler->parent_compiler = $compiler;
$_tpl->compiler->_tag_objects = $compiler->_tag_objects; $_tpl->compiler->_tag_objects = $compiler->_tag_objects;
$_tpl->compiler->inheritance = true; $_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); $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]); unset($compiler->template->compiled->file_dependency[$_tpl->source->uid]);
$compiler->template->tpl_function = array_merge($compiler->template->tpl_function, $_tpl->tpl_function); $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) { if ($_tpl->compiled->has_nocache_code) {
$compiler->template->compiled->has_nocache_code = true; $compiler->template->compiled->has_nocache_code = true;
} }

View File

@@ -52,7 +52,7 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
$compiler->_capture_stack[0][] = array($buffer, $assign, $append, $compiler->nocache); $compiler->_capture_stack[0][] = array($buffer, $assign, $append, $compiler->nocache);
// maybe nocache because of nocache variables // maybe nocache because of nocache variables
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache; $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
$_output = "<?php \$_smarty_tpl->_capture_stack[0][] = array($buffer, $assign, $append); ob_start(); ?>"; $_output = "<?php \$_smarty_tpl->_cache['capture_stack'][] = array($buffer, $assign, $append); ob_start(); ?>";
return $_output; 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]); list($buffer, $assign, $append, $compiler->nocache) = array_pop($compiler->_capture_stack[0]);
$_output = "<?php list(\$_capture_buffer, \$_capture_assign, \$_capture_append) = array_pop(\$_smarty_tpl->_capture_stack[0]);\n"; $_output = "<?php list(\$_capture_buffer, \$_capture_assign, \$_capture_append) = array_pop(\$_smarty_tpl->_cache['capture_stack']);\n";
$_output .= "if (!empty(\$_capture_buffer)) {\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_assign)) \$_smarty_tpl->assign(\$_capture_assign, ob_get_contents());\n";
$_output .= " if (isset( \$_capture_append)) \$_smarty_tpl->append( \$_capture_append, ob_get_contents());\n"; $_output .= " if (isset( \$_capture_append)) \$_smarty_tpl->append( \$_capture_append, ob_get_contents());\n";

View File

@@ -60,7 +60,7 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
// maybe nocache because of nocache variables or nocache plugin // maybe nocache because of nocache variables or nocache plugin
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache; $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
// compile code // compile code
$output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; $output = "<?php \$_smarty_tpl->smarty->_cache['tag_stack'][] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
} else { } else {
// must endblock be nocache? // must endblock be nocache?
if ($compiler->nocache) { if ($compiler->nocache) {
@@ -81,7 +81,7 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
} }
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre . $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre .
" echo {$function}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . $mod_post . " echo {$function}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . $mod_post .
" } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; " } array_pop(\$_smarty_tpl->smarty->_cache['tag_stack']);?>";
} }
return $output . "\n"; return $output . "\n";

View File

@@ -60,7 +60,7 @@ class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Inter
// maybe nocache because of nocache variables or nocache plugin // maybe nocache because of nocache variables or nocache plugin
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache; $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
// compile code // compile code
$output = "<?php \$_smarty_tpl->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 = "<?php \$_smarty_tpl->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 { } else {
$base_tag = substr($tag, 0, - 5); $base_tag = substr($tag, 0, - 5);
// must endblock be nocache? // must endblock be nocache?
@@ -82,7 +82,7 @@ class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Inter
} }
$output = "<?php \$_block_content = ob_get_contents(); ob_end_clean(); \$_block_repeat=false;" . $mod_pre . $output = "<?php \$_block_content = ob_get_contents(); ob_end_clean(); \$_block_repeat=false;" . $mod_pre .
" echo \$_smarty_tpl->smarty->registered_objects['{$base_tag}'][0]->{$method}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . " echo \$_smarty_tpl->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"; return $output . "\n";

View File

@@ -108,8 +108,7 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
} }
} }
} }
if (isset($compiler->template->variable_filters)) { foreach ($compiler->variable_filters as $filter) {
foreach ($compiler->template->variable_filters as $filter) {
if (count($filter) == 1 && if (count($filter) == 1 &&
($result = $this->compile_output_filter($compiler, $filter[0], $output)) !== false ($result = $this->compile_output_filter($compiler, $filter[0], $output)) !== false
) { ) {
@@ -120,7 +119,6 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
} }
} }
} }
}
$compiler->has_output = true; $compiler->has_output = true;
$output = "<?php echo {$output};?>"; $output = "<?php echo {$output};?>";

View File

@@ -69,11 +69,11 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C
$function = $tag_info[0]; $function = $tag_info[0];
// compile code // compile code
if (!is_array($function)) { if (!is_array($function)) {
$output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; $output = "<?php \$_smarty_tpl->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])) { } elseif (is_object($function[0])) {
$output = "<?php \$_smarty_tpl->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 = "<?php \$_smarty_tpl->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 { } else {
$output = "<?php \$_smarty_tpl->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 = "<?php \$_smarty_tpl->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 { } else {
// must endblock be nocache? // must endblock be nocache?
@@ -102,15 +102,15 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C
if (!is_array($function)) { if (!is_array($function)) {
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre . $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre .
" echo {$function}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat);" . $mod_post . " echo {$function}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat);" . $mod_post .
" } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; " } array_pop(\$_smarty_tpl->smarty->_cache['tag_stack']);?>";
} elseif (is_object($function[0])) { } elseif (is_object($function[0])) {
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre . $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre .
" echo \$_smarty_tpl->smarty->registered_plugins['block']['{$base_tag}'][0][0]->{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . " echo \$_smarty_tpl->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 { } else {
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre . $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre .
" echo {$function[0]}::{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . " echo {$function[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']);?>";
} }
} }

View File

@@ -27,8 +27,8 @@ class Smarty_Internal_Compile_Setfilter extends Smarty_Internal_CompileBase
*/ */
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{ {
$compiler->variable_filter_stack[] = $compiler->template->variable_filters; $compiler->variable_filter_stack[] = $compiler->variable_filters;
$compiler->template->variable_filters = $parameter['modifier_list']; $compiler->variable_filters = $parameter['modifier_list'];
// this tag does not return compiled code // this tag does not return compiled code
$compiler->has_code = false; $compiler->has_code = false;
@@ -58,9 +58,9 @@ class Smarty_Internal_Compile_Setfilterclose extends Smarty_Internal_CompileBase
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
// reset variable filter to previous state // reset variable filter to previous state
if (count($compiler->variable_filter_stack)) { 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 { } else {
$compiler->template->variable_filters = array(); $compiler->variable_filters = array();
} }
// this tag does not return compiled code // this tag does not return compiled code
$compiler->has_code = false; $compiler->has_code = false;

View File

@@ -48,13 +48,14 @@ class Smarty_Internal_Method_GetTags
} }
if (isset($tpl)) { if (isset($tpl)) {
$tpl->smarty = clone $tpl->smarty; $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->merge_compiled_includes = false;
$tpl->smarty->disableSecurity(); $tpl->smarty->disableSecurity();
$tpl->caching = false; $tpl->caching = false;
$tpl->loadCompiler(); $tpl->loadCompiler();
$tpl->compiler->compileTemplate($tpl); $tpl->compiler->compileTemplate($tpl);
return $tpl->used_tags; return $tpl->_cache['used_tags'];
} }
throw new SmartyException("Missing template specification"); throw new SmartyException("Missing template specification");
} }

View File

@@ -39,7 +39,7 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
preg_match('#^[.]{1,2}[\\\/]#', $file) preg_match('#^[.]{1,2}[\\\/]#', $file)
) { ) {
if ($_template->parent->source->type != 'file' && $_template->parent->source->type != 'extends' && 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}'"); throw new SmartyException("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'");
} }

View File

@@ -63,34 +63,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
*/ */
public $block_data = array(); 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 * Template Id
* *
@@ -302,16 +274,14 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
if (isset($this->smarty->security_policy)) { if (isset($this->smarty->security_policy)) {
$this->smarty->security_policy->startTemplate($this); $this->smarty->security_policy->startTemplate($this);
} }
array_unshift($this->_capture_stack, array());
// //
// render compiled or saved template code // render compiled or saved template code
// //
$unifunc($this); $unifunc($this);
// any unclosed {capture} tags ? // any unclosed {capture} tags ?
if (isset($this->_capture_stack[0][0])) { if (isset($this->_cache['capture_stack'][0])) {
$this->capture_error(); $this->capture_error();
} }
array_shift($this->_capture_stack);
if (isset($this->smarty->security_policy)) { if (isset($this->smarty->security_policy)) {
$this->smarty->security_policy->exitTemplate(); $this->smarty->security_policy->exitTemplate();
} }
@@ -321,7 +291,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
while (ob_get_level() > $level) { while (ob_get_level() > $level) {
ob_end_clean(); ob_end_clean();
} }
array_shift($this->_capture_stack);
if (isset($this->smarty->security_policy)) { if (isset($this->smarty->security_policy)) {
$this->smarty->security_policy->exitTemplate(); $this->smarty->security_policy->exitTemplate();
} }

View File

@@ -319,6 +319,13 @@ abstract class Smarty_Internal_TemplateCompilerBase
*/ */
public $variable_filter_stack = array(); public $variable_filter_stack = array();
/**
* variable filters for {setfilter} {/setfilter}
*
* @var array
*/
public $variable_filters = array();
/** /**
* Loop nesting count * Loop nesting count
* *
@@ -545,8 +552,8 @@ abstract class Smarty_Internal_TemplateCompilerBase
$this->has_code = true; $this->has_code = true;
$this->has_output = false; $this->has_output = false;
// log tag/attributes // log tag/attributes
if (isset($this->smarty->get_used_tags) && $this->smarty->get_used_tags) { if (isset($this->smarty->_cache['get_used_tags'])) {
$this->template->used_tags[] = array($tag, $args); $this->template->_cache['used_tags'][] = array($tag, $args);
} }
// check nocache option flag // check nocache option flag
if (in_array("'nocache'", $args) || in_array(array('nocache' => 'true'), $args) || if (in_array("'nocache'", $args) || in_array(array('nocache' => 'true'), $args) ||

View File

@@ -119,16 +119,14 @@ abstract class Smarty_Template_Resource_Base
if (isset($_template->smarty->security_policy)) { if (isset($_template->smarty->security_policy)) {
$_template->smarty->security_policy->startTemplate($_template); $_template->smarty->security_policy->startTemplate($_template);
} }
array_unshift($_template->_capture_stack, array());
// //
// render compiled or saved template code // render compiled or saved template code
// //
$unifunc($_template); $unifunc($_template);
// any unclosed {capture} tags ? // any unclosed {capture} tags ?
if (isset($_template->_capture_stack[0][0])) { if (isset($_template->_cache['capture_stack'][0])) {
$_template->capture_error(); $_template->capture_error();
} }
array_shift($_template->_capture_stack);
if (isset($_template->smarty->security_policy)) { if (isset($_template->smarty->security_policy)) {
$_template->smarty->security_policy->exitTemplate(); $_template->smarty->security_policy->exitTemplate();
} }
@@ -138,7 +136,6 @@ abstract class Smarty_Template_Resource_Base
while (ob_get_level() > $level) { while (ob_get_level() > $level) {
ob_end_clean(); 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(); $_template->smarty->security_policy->exitTemplate();
} }