mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 19:04:27 +02:00
- improvement add internal $joined_template_dir property instead computing it on the fly several times
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
===== trunk =====
|
===== trunk =====
|
||||||
|
03.10.2011
|
||||||
|
- improvement add internal $joined_template_dir property instead computing it on the fly several times
|
||||||
|
|
||||||
01.10.2011
|
01.10.2011
|
||||||
- improvement replaced most in_array() calls by more efficient isset() on array_flip()ed haystacks
|
- improvement replaced most in_array() calls by more efficient isset() on array_flip()ed haystacks
|
||||||
- improvement replaced some strlen($foo) > 3 calls by isset($foo[3])
|
- improvement replaced some strlen($foo) > 3 calls by isset($foo[3])
|
||||||
|
@@ -188,9 +188,14 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
|||||||
public $use_include_path = false;
|
public $use_include_path = false;
|
||||||
/**
|
/**
|
||||||
* template directory
|
* template directory
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $template_dir = array();
|
||||||
|
/**
|
||||||
|
* joined template directory string used in cache keys
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $template_dir = null;
|
public $joined_template_dir = null;
|
||||||
/**
|
/**
|
||||||
* default template handler
|
* default template handler
|
||||||
* @var callable
|
* @var callable
|
||||||
@@ -213,9 +218,9 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
|||||||
protected $compile_dir = null;
|
protected $compile_dir = null;
|
||||||
/**
|
/**
|
||||||
* plugins directory
|
* plugins directory
|
||||||
* @var string
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $plugins_dir = null;
|
protected $plugins_dir = array();
|
||||||
/**
|
/**
|
||||||
* cache directory
|
* cache directory
|
||||||
* @var string
|
* @var string
|
||||||
@@ -223,9 +228,9 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
|||||||
protected $cache_dir = null;
|
protected $cache_dir = null;
|
||||||
/**
|
/**
|
||||||
* config directory
|
* config directory
|
||||||
* @var string
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $config_dir = null;
|
protected $config_dir = array();
|
||||||
/**
|
/**
|
||||||
* force template compiling?
|
* force template compiling?
|
||||||
* @var boolean
|
* @var boolean
|
||||||
@@ -771,6 +776,7 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
|||||||
$this->template_dir[$k] = rtrim($v, '/\\') . DS;
|
$this->template_dir[$k] = rtrim($v, '/\\') . DS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->joined_template_dir = join(DIRECTORY_SEPARATOR, $this->template_dir);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -804,7 +810,7 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
|||||||
// append new directory
|
// append new directory
|
||||||
$this->template_dir[] = rtrim($template_dir, '/\\') . DS;
|
$this->template_dir[] = rtrim($template_dir, '/\\') . DS;
|
||||||
}
|
}
|
||||||
|
$this->joined_template_dir = join(DIRECTORY_SEPARATOR, $this->template_dir);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1148,7 +1154,7 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
|||||||
$cache_id = $cache_id === null ? $this->cache_id : $cache_id;
|
$cache_id = $cache_id === null ? $this->cache_id : $cache_id;
|
||||||
$compile_id = $compile_id === null ? $this->compile_id : $compile_id;
|
$compile_id = $compile_id === null ? $this->compile_id : $compile_id;
|
||||||
// already in template cache?
|
// already in template cache?
|
||||||
$_templateId = sha1(join(DIRECTORY_SEPARATOR, $this->getTemplateDir()).$template . $cache_id . $compile_id);
|
$_templateId = sha1($this->smarty->joined_template_dir.$template . $cache_id . $compile_id);
|
||||||
if ($do_clone) {
|
if ($do_clone) {
|
||||||
if (isset($this->template_objects[$_templateId])) {
|
if (isset($this->template_objects[$_templateId])) {
|
||||||
// return cached template object
|
// return cached template object
|
||||||
|
@@ -177,7 +177,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource {
|
|||||||
$uid = $tpl->source->uid;
|
$uid = $tpl->source->uid;
|
||||||
}
|
}
|
||||||
// remove from template cache
|
// remove from template cache
|
||||||
unset($smarty->template_objects[sha1(join(DIRECTORY_SEPARATOR, $smarty->getTemplateDir()) . $tpl->template_resource . $tpl->cache_id . $tpl->compile_id)]);
|
unset($smarty->template_objects[sha1($smarty->joined_template_dir . $tpl->template_resource . $tpl->cache_id . $tpl->compile_id)]);
|
||||||
}
|
}
|
||||||
return $uid;
|
return $uid;
|
||||||
}
|
}
|
||||||
|
@@ -154,10 +154,10 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource {
|
|||||||
if ($tpl->source->exists) {
|
if ($tpl->source->exists) {
|
||||||
$_resourcename_parts = basename(str_replace('^', '/', $tpl->cached->filepath));
|
$_resourcename_parts = basename(str_replace('^', '/', $tpl->cached->filepath));
|
||||||
// remove from template cache
|
// remove from template cache
|
||||||
unset($smarty->template_objects[sha1(join(DIRECTORY_SEPARATOR, $smarty->getTemplateDir()).$tpl->template_resource . $tpl->cache_id . $tpl->compile_id)]);
|
unset($smarty->template_objects[sha1($smarty->joined_template_dir.$tpl->template_resource . $tpl->cache_id . $tpl->compile_id)]);
|
||||||
} else {
|
} else {
|
||||||
// remove from template cache
|
// remove from template cache
|
||||||
unset($smarty->template_objects[sha1(join(DIRECTORY_SEPARATOR, $smarty->getTemplateDir()).$tpl->template_resource . $tpl->cache_id . $tpl->compile_id)]);
|
unset($smarty->template_objects[sha1($smarty->joined_template_dir.$tpl->template_resource . $tpl->cache_id . $tpl->compile_id)]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -240,7 +240,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
|||||||
public function getSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope)
|
public function getSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope)
|
||||||
{
|
{
|
||||||
// already in template cache?
|
// already in template cache?
|
||||||
$_templateId = sha1(join(DIRECTORY_SEPARATOR, $this->smarty->getTemplateDir()).$template . $cache_id . $compile_id);
|
$_templateId = sha1($this->smarty->joined_template_dir.$template . $cache_id . $compile_id);
|
||||||
if (isset($this->smarty->template_objects[$_templateId])) {
|
if (isset($this->smarty->template_objects[$_templateId])) {
|
||||||
// clone cached template object because of possible recursive call
|
// clone cached template object because of possible recursive call
|
||||||
$tpl = clone $this->smarty->template_objects[$_templateId];
|
$tpl = clone $this->smarty->template_objects[$_templateId];
|
||||||
@@ -593,7 +593,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
|||||||
// cache template object under a unique ID
|
// cache template object under a unique ID
|
||||||
// do not cache eval resources
|
// do not cache eval resources
|
||||||
if ($this->source->type != 'eval') {
|
if ($this->source->type != 'eval') {
|
||||||
$this->smarty->template_objects[sha1(join(DIRECTORY_SEPARATOR, $this->smarty->getTemplateDir()).$this->template_resource . $this->cache_id . $this->compile_id)] = $this;
|
$this->smarty->template_objects[sha1($this->smarty->joined_template_dir.$this->template_resource . $this->cache_id . $this->compile_id)] = $this;
|
||||||
}
|
}
|
||||||
return $this->source;
|
return $this->source;
|
||||||
|
|
||||||
|
@@ -193,10 +193,10 @@ class Smarty_Internal_Utility {
|
|||||||
$_resource_part_1 = basename(str_replace('^', '/', $tpl->compiled->filepath));
|
$_resource_part_1 = basename(str_replace('^', '/', $tpl->compiled->filepath));
|
||||||
$_resource_part_1_length = strlen($_resource_part_1);
|
$_resource_part_1_length = strlen($_resource_part_1);
|
||||||
// remove from template cache
|
// remove from template cache
|
||||||
unset($smarty->template_objects[sha1(join(DIRECTORY_SEPARATOR, $smarty->getTemplateDir()).$tpl->template_resource . $tpl->cache_id . $tpl->compile_id)]);
|
unset($smarty->template_objects[sha1($smarty->joined_template_dir.$tpl->template_resource . $tpl->cache_id . $tpl->compile_id)]);
|
||||||
} else {
|
} else {
|
||||||
// remove from template cache
|
// remove from template cache
|
||||||
unset($smarty->template_objects[sha1(join(DIRECTORY_SEPARATOR, $smarty->getTemplateDir()).$tpl->template_resource . $tpl->cache_id . $tpl->compile_id)]);
|
unset($smarty->template_objects[sha1($smarty->joined_template_dir.$tpl->template_resource . $tpl->cache_id . $tpl->compile_id)]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
$_resource_part_2 = str_replace('.php','.cache.php',$_resource_part_1);
|
$_resource_part_2 = str_replace('.php','.cache.php',$_resource_part_1);
|
||||||
|
@@ -399,7 +399,7 @@ abstract class Smarty_Resource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check runtime cache
|
// check runtime cache
|
||||||
$_cache_key_dir = join(DIRECTORY_SEPARATOR, $smarty->getTemplateDir());
|
$_cache_key_dir = $smarty->joined_template_dir;
|
||||||
$_cache_key = 'template|' . $template_resource;
|
$_cache_key = 'template|' . $template_resource;
|
||||||
if (!isset(self::$sources[$_cache_key_dir])) {
|
if (!isset(self::$sources[$_cache_key_dir])) {
|
||||||
self::$sources[$_cache_key_dir] = array();
|
self::$sources[$_cache_key_dir] = array();
|
||||||
@@ -599,7 +599,7 @@ class Smarty_Template_Source {
|
|||||||
public function getCompiled(Smarty_Internal_Template $_template)
|
public function getCompiled(Smarty_Internal_Template $_template)
|
||||||
{
|
{
|
||||||
// check runtime cache
|
// check runtime cache
|
||||||
$_cache_key_dir = join(DIRECTORY_SEPARATOR, $_template->smarty->getTemplateDir());
|
$_cache_key_dir = $_template->smarty->joined_template_dir;
|
||||||
$_cache_key = $_template->template_resource . '#' . $_template->compile_id;
|
$_cache_key = $_template->template_resource . '#' . $_template->compile_id;
|
||||||
if (!isset(Smarty_Resource::$compileds[$_cache_key_dir])) {
|
if (!isset(Smarty_Resource::$compileds[$_cache_key_dir])) {
|
||||||
Smarty_Resource::$compileds[$_cache_key_dir] = array();
|
Smarty_Resource::$compileds[$_cache_key_dir] = array();
|
||||||
|
Reference in New Issue
Block a user