- do not recompile evaluated templates if reused just with other data

- recompile config files when config properties did change
- some lexer/parser otimizations
This commit is contained in:
Uwe.Tews
2009-10-13 19:44:38 +00:00
parent 526337aa23
commit 5be5d4cf28
7 changed files with 1151 additions and 1155 deletions

View File

@@ -1,3 +1,8 @@
10/13/2009
- do not recompile evaluated templates if reused just with other data
- recompile config files when config properties did change
- some lexer/parser otimizations
10/11/2009 10/11/2009
- allow {block} tags inside included templates - allow {block} tags inside included templates
- bugfix for resource plugins in Smarty2 format - bugfix for resource plugins in Smarty2 format

View File

@@ -122,6 +122,8 @@ class Smarty extends Smarty_Internal_TemplateBase {
public $compile_error = false; public $compile_error = false;
// caching enabled // caching enabled
public $caching = false; public $caching = false;
// merge compiled includea
public $merge_compiled_includes = true;
// cache lifetime // cache lifetime
public $cache_lifetime = 0; public $cache_lifetime = 0;
// force cache file creation // force cache file creation
@@ -151,7 +153,7 @@ class Smarty extends Smarty_Internal_TemplateBase {
// config var settings // config var settings
public $config_overwrite = true; //Controls whether variables with the same name overwrite each other. public $config_overwrite = true; //Controls whether variables with the same name overwrite each other.
public $config_booleanize = true; //Controls whether config values of on/true/yes and off/false/no get converted to boolean public $config_booleanize = true; //Controls whether config values of on/true/yes and off/false/no get converted to boolean
public $config_read_hidden = true; //Controls whether hidden config sections/vars are read from the file. public $config_read_hidden = true; //Controls whether hidden config sections/vars are read from the file.
// config vars // config vars
public $config_vars = array(); public $config_vars = array();
// assigned tpl vars // assigned tpl vars
@@ -179,7 +181,7 @@ class Smarty extends Smarty_Internal_TemplateBase {
// check If-Modified-Since headers // check If-Modified-Since headers
public $cache_modified_check = false; public $cache_modified_check = false;
// cached objects // cached objects
public $resource_objects = array(); public $resource_objects = array();
// registered plugins // registered plugins
public $registered_plugins = array(); public $registered_plugins = array();
// plugin search order // plugin search order
@@ -286,6 +288,7 @@ class Smarty extends Smarty_Internal_TemplateBase {
*/ */
public function fetch($template, $cache_id = null, $compile_id = null, $parent = null) public function fetch($template, $cache_id = null, $compile_id = null, $parent = null)
{ {
$this->checkDebugging();
if (is_object($cache_id)) { if (is_object($cache_id)) {
$parent = $cache_id; $parent = $cache_id;
$cache_id = null; $cache_id = null;
@@ -315,18 +318,15 @@ class Smarty extends Smarty_Internal_TemplateBase {
* @param object $parent next higher level of Smarty variables * @param object $parent next higher level of Smarty variables
*/ */
public function display($template, $cache_id = null, $compile_id = null, $parent = null) public function display($template, $cache_id = null, $compile_id = null, $parent = null)
{ {
if (is_object($cache_id)) { if (is_object($cache_id)) {
$parent = $cache_id; $parent = $cache_id;
$cache_id = null; $cache_id = null;
} }
// display template // display template
echo $this->fetch ($template, $cache_id, $compile_id, $parent); echo $this->fetch ($template, $cache_id, $compile_id, $parent);
// debug output? // debug output
if ($this->debugging) { $this->displayDebugInfo();
$this->loadPlugin('Smarty_Internal_Debug');
Smarty_Internal_Debug::display_debug($this);
}
return true; return true;
} }
@@ -340,6 +340,7 @@ class Smarty extends Smarty_Internal_TemplateBase {
*/ */
public function is_cached($template, $cache_id = null, $compile_id = null) public function is_cached($template, $cache_id = null, $compile_id = null)
{ {
$this->checkDebugging();
if (!($template instanceof $this->template_class)) { if (!($template instanceof $this->template_class)) {
$template = $this->createTemplate ($template, $cache_id, $compile_id, $this); $template = $this->createTemplate ($template, $cache_id, $compile_id, $this);
} }
@@ -492,6 +493,26 @@ class Smarty extends Smarty_Internal_TemplateBase {
return set_exception_handler($handler); return set_exception_handler($handler);
} }
/**
* Check if debugging handler must be loaded
*/
public function checkDebugging()
{
if ($this->debugging && !class_exists('Smarty_Internal_Debug', false)) {
$this->loadPlugin('Smarty_Internal_Debug');
}
}
/**
* Display debug info
*/
public function displayDebugInfo()
{
if ($this->debugging) {
Smarty_Internal_Debug::display_debug($this);
}
}
/** /**
* trigger Smarty error * trigger Smarty error
* *
@@ -499,8 +520,7 @@ class Smarty extends Smarty_Internal_TemplateBase {
* @param integer $error_type * @param integer $error_type
*/ */
public function trigger_error($error_msg, $error_type = E_USER_WARNING) public function trigger_error($error_msg, $error_type = E_USER_WARNING)
{ {
// trigger_error("Smarty error: $error_msg", $error_type);
throw new Exception("Smarty error: $error_msg"); throw new Exception("Smarty error: $error_msg");
} }

View File

@@ -30,7 +30,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase {
// save posible attributes // save posible attributes
$include_file = $_attr['file']; $include_file = $_attr['file'];
$has_compiled_template = false; $has_compiled_template = false;
if (true) { if ($compiler->smarty->merge_compiled_includes) {
// check if compiled code can be merged // check if compiled code can be merged
if (strpos($include_file, '$_smarty_tpl') === false) { if (strpos($include_file, '$_smarty_tpl') === false) {
eval("\$tmp = $include_file;"); eval("\$tmp = $include_file;");
@@ -134,20 +134,21 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase {
$_output .= "\$_template->caching = $_caching;"; $_output .= "\$_template->caching = $_caching;";
// was there an assign attribute // was there an assign attribute
if (isset($_assign)) { if (isset($_assign)) {
$_output .= "\$_smarty_tpl->assign($_assign,\$_smarty_tpl->smarty->fetch(\$_template)); ?>"; $_output .= "\$_smarty_tpl->assign($_assign,\$_template->fetch()); ?>";
} else { } else {
if ($has_compiled_template) { if ($has_compiled_template) {
$_output .= " \$_tpl_stack[] = \$_smarty_tpl; \$_smarty_tpl = \$_template;?>\n"; $_output .= " \$_tpl_stack[] = \$_smarty_tpl; \$_smarty_tpl = \$_template;?>\n";
$_output .= $compiled_tpl . "<?php /* End of included template \"" . $tpl->getTemplateFilepath() . "\" */ ?>";; $_output .= $compiled_tpl . "<?php /* End of included template \"" . $tpl->getTemplateFilepath() . "\" */ ?>";;
$_output .= "<?php \$_smarty_tpl = array_pop(\$_tpl_stack);?>"; $_output .= "<?php \$_smarty_tpl = array_pop(\$_tpl_stack);?>";
} else { } else {
$_output .= " echo \$_smarty_tpl->smarty->fetch(\$_template); ?>"; $_output .= " echo \$_template->fetch(); ?>";
} }
} }
if ($_parent_scope != SMARTY_LOCAL_SCOPE) { if ($_parent_scope != SMARTY_LOCAL_SCOPE) {
$_output .= "<?php \$_template->updateParentVariables($_parent_scope); ?>"; $_output .= "<?php \$_template->updateParentVariables($_parent_scope); ?>";
} }
return $_output; $_output .= "<?php unset(\$_template); ?>";
return $_output;
} }
} }

View File

@@ -131,7 +131,9 @@ class Smarty_Internal_Config {
} }
public function buildCompiledFilepath() public function buildCompiledFilepath()
{ {
$_filepath = (string)abs(crc32($this->config_resource_name)); $_flag = (int)$this->smarty->config_read_hidden + (int)$this->smarty->config_booleanize * 2 +
(int)$this->smarty->config_overwrite * 4;
$_filepath = (string)abs(crc32($this->config_resource_name . $_flag));
// if use_sub_dirs, break file into directories // if use_sub_dirs, break file into directories
if ($this->smarty->use_sub_dirs) { if ($this->smarty->use_sub_dirs) {
$_filepath = substr($_filepath, 0, 3) . DS $_filepath = substr($_filepath, 0, 3) . DS

View File

@@ -415,7 +415,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
public function renderTemplate () public function renderTemplate ()
{ {
if ($this->usesCompiler()) { if ($this->usesCompiler()) {
if ($this->mustCompile()) { if ($this->mustCompile() && $this->compiled_template === null) {
$this->compileTemplateSource(); $this->compileTemplateSource();
} }
$_smarty_tpl = $this; $_smarty_tpl = $this;

View File

@@ -82,6 +82,7 @@ class Smarty_Internal_Templatelexer
$this->rdel = preg_quote($this->smarty->right_delimiter); $this->rdel = preg_quote($this->smarty->right_delimiter);
$this->smarty_token_names['LDEL'] = $this->smarty->left_delimiter; $this->smarty_token_names['LDEL'] = $this->smarty->left_delimiter;
$this->smarty_token_names['RDEL'] = $this->smarty->right_delimiter; $this->smarty_token_names['RDEL'] = $this->smarty->right_delimiter;
$this->tag = false;
} }
public static function &instance($new_instance = null) public static function &instance($new_instance = null)
{ {
@@ -462,11 +463,13 @@ class Smarty_Internal_Templatelexer
{ {
$this->token = Smarty_Internal_Templateparser::TP_LDEL; $this->token = Smarty_Internal_Templateparser::TP_LDEL;
$this->tag = true;
} }
function yy_r1_19($yy_subpatterns) function yy_r1_19($yy_subpatterns)
{ {
$this->token = Smarty_Internal_Templateparser::TP_RDEL; $this->token = Smarty_Internal_Templateparser::TP_RDEL;
$this->tag = false;
} }
function yy_r1_20($yy_subpatterns) function yy_r1_20($yy_subpatterns)
{ {

File diff suppressed because it is too large Load Diff