mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
improve performance
This commit is contained in:
@@ -88,15 +88,15 @@ class Smarty_Template_Cached extends Smarty_Template_Resource_Base
|
||||
*/
|
||||
static function load(Smarty_Internal_Template $_template)
|
||||
{
|
||||
$_template->cached = $cached = new Smarty_Template_Cached($_template);
|
||||
$cached->handler->populate($cached, $_template);
|
||||
$_template->cached = new Smarty_Template_Cached($_template);
|
||||
$_template->cached->handler->populate($_template->cached, $_template);
|
||||
// caching enabled ?
|
||||
if (!($_template->caching == Smarty::CACHING_LIFETIME_CURRENT ||
|
||||
$_template->caching == Smarty::CACHING_LIFETIME_SAVED) || $_template->source->recompiled
|
||||
) {
|
||||
$cached->valid = false;
|
||||
$_template->cached->valid = false;
|
||||
}
|
||||
return $cached;
|
||||
return $_template->cached;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -36,28 +36,26 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
|
||||
*/
|
||||
static function load($_template)
|
||||
{
|
||||
$smarty = $_template->smarty;
|
||||
$source = $_template->source;
|
||||
// check runtime cache
|
||||
if (!$source->recompiled && ($smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON)) {
|
||||
$_cache_key = $source->unique_resource . '#';
|
||||
if (!$_template->source->recompiled && ($_template->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON)) {
|
||||
$_cache_key = $_template->source->unique_resource . '#';
|
||||
if ($_template->caching) {
|
||||
$_cache_key .= 'caching#';
|
||||
}
|
||||
$_cache_key .= $_template->compile_id;
|
||||
if (isset($source->compileds[$_cache_key])) {
|
||||
return $source->compileds[$_cache_key];
|
||||
if (isset($_template->source->compileds[$_cache_key])) {
|
||||
return $_template->source->compileds[$_cache_key];
|
||||
}
|
||||
}
|
||||
$compiled = new Smarty_Template_Compiled();
|
||||
if (method_exists($source->handler, 'populateCompiledFilepath')) {
|
||||
$source->handler->populateCompiledFilepath($compiled, $_template);
|
||||
if (method_exists($_template->source->handler, 'populateCompiledFilepath')) {
|
||||
$_template->source->handler->populateCompiledFilepath($compiled, $_template);
|
||||
} else {
|
||||
$compiled->populateCompiledFilepath($_template);
|
||||
}
|
||||
// runtime cache
|
||||
if (!$source->recompiled && ($smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON)) {
|
||||
$source->compileds[$_cache_key] = $compiled;
|
||||
if (!$_template->source->recompiled && ($_template->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON)) {
|
||||
$_template->source->compileds[$_cache_key] = $compiled;
|
||||
}
|
||||
return $compiled;
|
||||
}
|
||||
|
@@ -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)
|
||||
{
|
||||
static $_incompatible_resources = array('extends' => true, 'php' => true);
|
||||
$smarty = $_template->smarty;
|
||||
$template_resource = $_template->template_resource;
|
||||
if (empty($template_resource)) {
|
||||
throw new SmartyException('Missing config name');
|
||||
}
|
||||
// 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
|
||||
if (isset($_incompatible_resources[$type])) {
|
||||
throw new SmartyException ("Unable to use resource '{$type}' for config");
|
||||
}
|
||||
$resource = Smarty_Resource::load($smarty, $type);
|
||||
$source = new Smarty_Template_Config($resource, $smarty, $template_resource, $type, $name);
|
||||
$resource = Smarty_Resource::load($_template->smarty, $type);
|
||||
$source = new Smarty_Template_Config($resource, $_template->smarty, $template_resource, $type, $name);
|
||||
$resource->populate($source, $_template);
|
||||
if (!$source->exists && isset($_template->smarty->default_config_handler_func)) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user