improve performance

This commit is contained in:
uwetews
2015-08-18 02:57:10 +02:00
parent 457a0486f5
commit 5f7b5a45ac
3 changed files with 16 additions and 19 deletions

View File

@@ -88,15 +88,15 @@ class Smarty_Template_Cached extends Smarty_Template_Resource_Base
*/ */
static function load(Smarty_Internal_Template $_template) static function load(Smarty_Internal_Template $_template)
{ {
$_template->cached = $cached = new Smarty_Template_Cached($_template); $_template->cached = new Smarty_Template_Cached($_template);
$cached->handler->populate($cached, $_template); $_template->cached->handler->populate($_template->cached, $_template);
// caching enabled ? // caching enabled ?
if (!($_template->caching == Smarty::CACHING_LIFETIME_CURRENT || if (!($_template->caching == Smarty::CACHING_LIFETIME_CURRENT ||
$_template->caching == Smarty::CACHING_LIFETIME_SAVED) || $_template->source->recompiled $_template->caching == Smarty::CACHING_LIFETIME_SAVED) || $_template->source->recompiled
) { ) {
$cached->valid = false; $_template->cached->valid = false;
} }
return $cached; return $_template->cached;
} }
/** /**

View File

@@ -36,28 +36,26 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
*/ */
static function load($_template) static function load($_template)
{ {
$smarty = $_template->smarty;
$source = $_template->source;
// check runtime cache // check runtime cache
if (!$source->recompiled && ($smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON)) { if (!$_template->source->recompiled && ($_template->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON)) {
$_cache_key = $source->unique_resource . '#'; $_cache_key = $_template->source->unique_resource . '#';
if ($_template->caching) { if ($_template->caching) {
$_cache_key .= 'caching#'; $_cache_key .= 'caching#';
} }
$_cache_key .= $_template->compile_id; $_cache_key .= $_template->compile_id;
if (isset($source->compileds[$_cache_key])) { if (isset($_template->source->compileds[$_cache_key])) {
return $source->compileds[$_cache_key]; return $_template->source->compileds[$_cache_key];
} }
} }
$compiled = new Smarty_Template_Compiled(); $compiled = new Smarty_Template_Compiled();
if (method_exists($source->handler, 'populateCompiledFilepath')) { if (method_exists($_template->source->handler, 'populateCompiledFilepath')) {
$source->handler->populateCompiledFilepath($compiled, $_template); $_template->source->handler->populateCompiledFilepath($compiled, $_template);
} else { } else {
$compiled->populateCompiledFilepath($_template); $compiled->populateCompiledFilepath($_template);
} }
// runtime cache // runtime cache
if (!$source->recompiled && ($smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON)) { if (!$_template->source->recompiled && ($_template->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON)) {
$source->compileds[$_cache_key] = $compiled; $_template->source->compileds[$_cache_key] = $compiled;
} }
return $compiled; return $compiled;
} }

View File

@@ -92,24 +92,23 @@ class Smarty_Template_Config extends Smarty_Template_Source
public static function load(Smarty_Internal_Template $_template = null, Smarty $smarty = null, $template_resource = null) public static function load(Smarty_Internal_Template $_template = null, Smarty $smarty = null, $template_resource = null)
{ {
static $_incompatible_resources = array('extends' => true, 'php' => true); static $_incompatible_resources = array('extends' => true, 'php' => true);
$smarty = $_template->smarty;
$template_resource = $_template->template_resource; $template_resource = $_template->template_resource;
if (empty($template_resource)) { if (empty($template_resource)) {
throw new SmartyException('Missing config name'); throw new SmartyException('Missing config name');
} }
// parse resource_name, load resource handler // parse resource_name, load resource handler
list($name, $type) = Smarty_Resource::parseResourceName($template_resource, $smarty->default_config_type); list($name, $type) = Smarty_Resource::parseResourceName($template_resource, $_template->smarty->default_config_type);
// make sure configs are not loaded via anything smarty can't handle // make sure configs are not loaded via anything smarty can't handle
if (isset($_incompatible_resources[$type])) { if (isset($_incompatible_resources[$type])) {
throw new SmartyException ("Unable to use resource '{$type}' for config"); throw new SmartyException ("Unable to use resource '{$type}' for config");
} }
$resource = Smarty_Resource::load($smarty, $type); $resource = Smarty_Resource::load($_template->smarty, $type);
$source = new Smarty_Template_Config($resource, $smarty, $template_resource, $type, $name); $source = new Smarty_Template_Config($resource, $_template->smarty, $template_resource, $type, $name);
$resource->populate($source, $_template); $resource->populate($source, $_template);
if (!$source->exists && isset($_template->smarty->default_config_handler_func)) { if (!$source->exists && isset($_template->smarty->default_config_handler_func)) {
Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source); Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source);
} }
$source->unique_resource = $resource->buildUniqueResourceName($smarty, $name, true); $source->unique_resource = $resource->buildUniqueResourceName($_template->smarty, $name, true);
return $source; return $source;
} }
} }