From 12e8593760e25f0475f21bd087e5ccb98fc5f57a Mon Sep 17 00:00:00 2001 From: "uwe.tews@googlemail.com" Date: Mon, 3 Oct 2011 19:02:44 +0000 Subject: [PATCH] - improvement add internal $joined_template_dir property instead computing it on the fly several times --- change_log.txt | 3 +++ libs/Smarty.class.php | 20 ++++++++++++------- .../smarty_cacheresource_keyvaluestore.php | 2 +- .../smarty_internal_cacheresource_file.php | 4 ++-- libs/sysplugins/smarty_internal_template.php | 4 ++-- libs/sysplugins/smarty_internal_utility.php | 4 ++-- libs/sysplugins/smarty_resource.php | 4 ++-- 7 files changed, 25 insertions(+), 16 deletions(-) diff --git a/change_log.txt b/change_log.txt index 7d4647e3..46add0e6 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@ ===== trunk ===== +03.10.2011 +- improvement add internal $joined_template_dir property instead computing it on the fly several times + 01.10.2011 - 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]) diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 3edae0fb..8060f3b9 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -188,9 +188,14 @@ class Smarty extends Smarty_Internal_TemplateBase { public $use_include_path = false; /** * template directory + * @var array + */ + protected $template_dir = array(); + /** + * joined template directory string used in cache keys * @var string */ - protected $template_dir = null; + public $joined_template_dir = null; /** * default template handler * @var callable @@ -213,9 +218,9 @@ class Smarty extends Smarty_Internal_TemplateBase { protected $compile_dir = null; /** * plugins directory - * @var string + * @var array */ - protected $plugins_dir = null; + protected $plugins_dir = array(); /** * cache directory * @var string @@ -223,9 +228,9 @@ class Smarty extends Smarty_Internal_TemplateBase { protected $cache_dir = null; /** * config directory - * @var string + * @var array */ - protected $config_dir = null; + protected $config_dir = array(); /** * force template compiling? * @var boolean @@ -771,6 +776,7 @@ class Smarty extends Smarty_Internal_TemplateBase { $this->template_dir[$k] = rtrim($v, '/\\') . DS; } + $this->joined_template_dir = join(DIRECTORY_SEPARATOR, $this->template_dir); return $this; } @@ -804,7 +810,7 @@ class Smarty extends Smarty_Internal_TemplateBase { // append new directory $this->template_dir[] = rtrim($template_dir, '/\\') . DS; } - + $this->joined_template_dir = join(DIRECTORY_SEPARATOR, $this->template_dir); return $this; } @@ -1148,7 +1154,7 @@ class Smarty extends Smarty_Internal_TemplateBase { $cache_id = $cache_id === null ? $this->cache_id : $cache_id; $compile_id = $compile_id === null ? $this->compile_id : $compile_id; // 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 (isset($this->template_objects[$_templateId])) { // return cached template object diff --git a/libs/sysplugins/smarty_cacheresource_keyvaluestore.php b/libs/sysplugins/smarty_cacheresource_keyvaluestore.php index 6d2d3b83..7d9cfcc0 100644 --- a/libs/sysplugins/smarty_cacheresource_keyvaluestore.php +++ b/libs/sysplugins/smarty_cacheresource_keyvaluestore.php @@ -177,7 +177,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource { $uid = $tpl->source->uid; } // 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; } diff --git a/libs/sysplugins/smarty_internal_cacheresource_file.php b/libs/sysplugins/smarty_internal_cacheresource_file.php index a5cd9f8b..9c4d0326 100644 --- a/libs/sysplugins/smarty_internal_cacheresource_file.php +++ b/libs/sysplugins/smarty_internal_cacheresource_file.php @@ -154,10 +154,10 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource { if ($tpl->source->exists) { $_resourcename_parts = basename(str_replace('^', '/', $tpl->cached->filepath)); // 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 { // 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; } } diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index 0dde3928..c5204a73 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -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) { // 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])) { // clone cached template object because of possible recursive call $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 // do not cache eval resources 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; diff --git a/libs/sysplugins/smarty_internal_utility.php b/libs/sysplugins/smarty_internal_utility.php index 66cb7613..1d3ced38 100644 --- a/libs/sysplugins/smarty_internal_utility.php +++ b/libs/sysplugins/smarty_internal_utility.php @@ -193,10 +193,10 @@ class Smarty_Internal_Utility { $_resource_part_1 = basename(str_replace('^', '/', $tpl->compiled->filepath)); $_resource_part_1_length = strlen($_resource_part_1); // 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 { // 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; } $_resource_part_2 = str_replace('.php','.cache.php',$_resource_part_1); diff --git a/libs/sysplugins/smarty_resource.php b/libs/sysplugins/smarty_resource.php index 69a4ba42..b2f89701 100644 --- a/libs/sysplugins/smarty_resource.php +++ b/libs/sysplugins/smarty_resource.php @@ -399,7 +399,7 @@ abstract class Smarty_Resource { } // check runtime cache - $_cache_key_dir = join(DIRECTORY_SEPARATOR, $smarty->getTemplateDir()); + $_cache_key_dir = $smarty->joined_template_dir; $_cache_key = 'template|' . $template_resource; if (!isset(self::$sources[$_cache_key_dir])) { self::$sources[$_cache_key_dir] = array(); @@ -599,7 +599,7 @@ class Smarty_Template_Source { public function getCompiled(Smarty_Internal_Template $_template) { // 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; if (!isset(Smarty_Resource::$compileds[$_cache_key_dir])) { Smarty_Resource::$compileds[$_cache_key_dir] = array();