- speed and size optimizations

This commit is contained in:
uwetews
2015-10-18 04:54:09 +02:00
parent 8dc2a0af7c
commit c99fe144f6
4 changed files with 30 additions and 23 deletions

View File

@@ -2,7 +2,8 @@
18.10.2015 18.10.2015
- optimize filepath normalization - optimize filepath normalization
- rework of template inheritance - rework of template inheritance
- speed and size optimizations
18.09.2015 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 - bugfix {if $foo instanceof $bar} failed to compile if 2nd value is a variable https://github.com/smarty-php/smarty/issues/92

View File

@@ -65,10 +65,9 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom
* @param string $parser_class class name * @param string $parser_class class name
* @param Smarty $smarty global instance * @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($smarty);
parent::__construct();
// get required plugins // get required plugins
$this->lexer_class = $lexer_class; $this->lexer_class = $lexer_class;
$this->parser_class = $parser_class; $this->parser_class = $parser_class;

View File

@@ -186,19 +186,20 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
$this->compiled->render($this); $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 // display or fetch
if ($display) { if ($display) {
if ($this->caching && $this->smarty->cache_modified_check) { if ($this->caching && $this->smarty->cache_modified_check) {
$this->cached->cacheModifiedCheck($this, isset($content) ? $content : ob_get_clean()); $this->cached->cacheModifiedCheck($this, isset($content) ? $content : ob_get_clean());
} else { } 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) { if ($this->smarty->debugging) {
$this->smarty->_debug->end_template($this); $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 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; $cache_tpl_obj = true;
} }
if (isset($tpl->compiled->file_dependency[$uid])) { if (isset($tpl->compiled->file_dependency[$uid])) {
$info = $tpl->compiled->file_dependency[$uid]; list($filepath, $timestamp, $resource) = $tpl->compiled->file_dependency[$uid];
$tpl->source = $tpl->source =
new Smarty_Template_Source(isset($tpl->smarty->_cache['resource_handlers'][$info[2]]) ? new Smarty_Template_Source(isset($tpl->smarty->_cache['resource_handlers'][$resource]) ?
$tpl->smarty->_cache['resource_handlers'][$info[2]] : $tpl->smarty->_cache['resource_handlers'][$resource] :
Smarty_Resource::load($tpl->smarty, $info[2]), $tpl->smarty, Smarty_Resource::load($tpl->smarty, $resource), $tpl->smarty,
$info[0], $info[2], $info[0]); $filepath, $resource, $filepath);
$tpl->source->filepath = $info[0]; $tpl->source->filepath = $filepath;
$tpl->source->timestamp = $info[1]; $tpl->source->timestamp = $timestamp;
$tpl->source->exist = true; $tpl->source->exist = true;
$tpl->source->uid = $uid; $tpl->source->uid = $uid;
} else { } else {

View File

@@ -155,7 +155,7 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
!empty($_template->parent->compiled->includes) && !empty($_template->parent->compiled->includes) &&
$_template->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_AUTOMATIC && $_template->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_AUTOMATIC &&
!$_template->source->handler->recompiled && $_template->source->type != 'string' && !$_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) { foreach ($_template->parent->compiled->includes as $key => $count) {
$_template->compiled->includes[$key] = $_template->compiled->includes[$key] =
@@ -164,7 +164,7 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
} }
$key = $_template->source->type . ':' . $_template->source->name; $key = $_template->source->type . ':' . $_template->source->name;
if (isset($_template->compiled->includes[$key]) && $_template->compiled->includes[$key] > 1) { 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; $this->processed = true;
@@ -182,7 +182,7 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
opcache_invalidate($_template->compiled->filepath); opcache_invalidate($_template->compiled->filepath);
} }
$_smarty_tpl = $_template; $_smarty_tpl = $_template;
if (strpos(phpversion(), 'hhvm') !== false) { if (defined('HHVM_VERSION')) {
Smarty_Internal_Extension_Hhvm::includeHhvm($_template, $_template->compiled->filepath); Smarty_Internal_Extension_Hhvm::includeHhvm($_template, $_template->compiled->filepath);
} else { } else {
include($_template->compiled->filepath); include($_template->compiled->filepath);