From c99fe144f6608e83bc05acfa60cc9d65f1ce66bc Mon Sep 17 00:00:00 2001 From: uwetews Date: Sun, 18 Oct 2015 04:54:09 +0200 Subject: [PATCH] - speed and size optimizations --- change_log.txt | 3 +- ...smarty_internal_smartytemplatecompiler.php | 5 +-- libs/sysplugins/smarty_internal_template.php | 39 +++++++++++-------- libs/sysplugins/smarty_template_compiled.php | 6 +-- 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/change_log.txt b/change_log.txt index 3b1bdd07..c260e26c 100644 --- a/change_log.txt +++ b/change_log.txt @@ -2,7 +2,8 @@ 18.10.2015 - optimize filepath normalization - rework of template inheritance - + - speed and size optimizations + 18.09.2015 - bugfix {if $foo instanceof $bar} failed to compile if 2nd value is a variable https://github.com/smarty-php/smarty/issues/92 diff --git a/libs/sysplugins/smarty_internal_smartytemplatecompiler.php b/libs/sysplugins/smarty_internal_smartytemplatecompiler.php index 5f33fff5..116bbea7 100644 --- a/libs/sysplugins/smarty_internal_smartytemplatecompiler.php +++ b/libs/sysplugins/smarty_internal_smartytemplatecompiler.php @@ -65,10 +65,9 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom * @param string $parser_class class name * @param Smarty $smarty global instance */ - public function __construct($lexer_class, $parser_class, $smarty) + public function __construct($lexer_class, $parser_class, Smarty $smarty) { - $this->smarty = $smarty; - parent::__construct(); + parent::__construct($smarty); // get required plugins $this->lexer_class = $lexer_class; $this->parser_class = $parser_class; diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index 16fca678..0daac390 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -186,19 +186,20 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase $this->compiled->render($this); } - $content = null; - if ((!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled) && - !$no_output_filter && - (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output'])) - ) { - $content = Smarty_Internal_Filter_Handler::runFilter('output', ob_get_clean(), $this); - } // display or fetch if ($display) { if ($this->caching && $this->smarty->cache_modified_check) { $this->cached->cacheModifiedCheck($this, isset($content) ? $content : ob_get_clean()); } else { - echo isset($content) ? $content : ob_get_clean(); + if ((!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled) && + !$no_output_filter && (isset($this->smarty->autoload_filters['output']) || + isset($this->smarty->registered_filters['output'])) + ) { + echo Smarty_Internal_Filter_Handler::runFilter('output', ob_get_clean(), $this); + } else { + ob_end_flush(); + flush(); + } } if ($this->smarty->debugging) { $this->smarty->_debug->end_template($this); @@ -239,8 +240,14 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase } } } + if (!$no_output_filter && + (!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled) && + (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output'])) + ) { + return Smarty_Internal_Filter_Handler::runFilter('output', ob_get_clean(), $this); + } // return cache content - return $content === null ? null : $content; + return null; } } @@ -337,14 +344,14 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase $cache_tpl_obj = true; } if (isset($tpl->compiled->file_dependency[$uid])) { - $info = $tpl->compiled->file_dependency[$uid]; + list($filepath, $timestamp, $resource) = $tpl->compiled->file_dependency[$uid]; $tpl->source = - new Smarty_Template_Source(isset($tpl->smarty->_cache['resource_handlers'][$info[2]]) ? - $tpl->smarty->_cache['resource_handlers'][$info[2]] : - Smarty_Resource::load($tpl->smarty, $info[2]), $tpl->smarty, - $info[0], $info[2], $info[0]); - $tpl->source->filepath = $info[0]; - $tpl->source->timestamp = $info[1]; + new Smarty_Template_Source(isset($tpl->smarty->_cache['resource_handlers'][$resource]) ? + $tpl->smarty->_cache['resource_handlers'][$resource] : + Smarty_Resource::load($tpl->smarty, $resource), $tpl->smarty, + $filepath, $resource, $filepath); + $tpl->source->filepath = $filepath; + $tpl->source->timestamp = $timestamp; $tpl->source->exist = true; $tpl->source->uid = $uid; } else { diff --git a/libs/sysplugins/smarty_template_compiled.php b/libs/sysplugins/smarty_template_compiled.php index 641cccd3..f9514473 100644 --- a/libs/sysplugins/smarty_template_compiled.php +++ b/libs/sysplugins/smarty_template_compiled.php @@ -155,7 +155,7 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base !empty($_template->parent->compiled->includes) && $_template->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_AUTOMATIC && !$_template->source->handler->recompiled && $_template->source->type != 'string' && - !isset($_template->smarty->_cache['template_objects'][$_template->_getTemplateId()]) + (!isset($_template->smarty->_cache['template_objects']) || !isset($_template->smarty->_cache['template_objects'][$_template->_getTemplateId()])) ) { foreach ($_template->parent->compiled->includes as $key => $count) { $_template->compiled->includes[$key] = @@ -164,7 +164,7 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base } $key = $_template->source->type . ':' . $_template->source->name; if (isset($_template->compiled->includes[$key]) && $_template->compiled->includes[$key] > 1) { - $_template->smarty->_cache['template_objects'][$_template->templateId] = $_template; + $_template->smarty->_cache['template_objects'][isset($_template->templateId) ? $_template->templateId : $_template->_getTemplateId()] = $_template; } } $this->processed = true; @@ -182,7 +182,7 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base opcache_invalidate($_template->compiled->filepath); } $_smarty_tpl = $_template; - if (strpos(phpversion(), 'hhvm') !== false) { + if (defined('HHVM_VERSION')) { Smarty_Internal_Extension_Hhvm::includeHhvm($_template, $_template->compiled->filepath); } else { include($_template->compiled->filepath);