From dc592e5a4477de2489a5c407be93d370141a90fa Mon Sep 17 00:00:00 2001 From: "Uwe.Tews" Date: Tue, 20 Oct 2009 17:09:22 +0000 Subject: [PATCH] - check at compile time for variable filter to improve rendering speed if no filter is used - fixed bug at combination of {elseif} tag and {...} in double quoted strings of static class parameter --- change_log.txt | 4 ++++ libs/sysplugins/internal.compile_else.php | 4 ++-- libs/sysplugins/internal.compile_elseif.php | 16 ++++++++++++---- libs/sysplugins/internal.compile_if.php | 2 +- libs/sysplugins/internal.compile_ifclose.php | 8 +++++--- .../internal.compile_print_expression.php | 6 +++++- libs/sysplugins/internal.templateparser.php | 14 +++++++------- 7 files changed, 36 insertions(+), 18 deletions(-) diff --git a/change_log.txt b/change_log.txt index 2cd33b25..ae4a3ff3 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,3 +1,7 @@ +10/20/2009 +- check at compile time for variable filter to improve rendering speed if no filter is used +- fixed bug at combination of {elseif} tag and {...} in double quoted strings of static class parameter + 10/19/2009 - fixed compiled template merging on variable double quoted strings as name - fixed bug in caching mode 2 and cache_lifetime -1 diff --git a/libs/sysplugins/internal.compile_else.php b/libs/sysplugins/internal.compile_else.php index 420522e3..0b419aa6 100644 --- a/libs/sysplugins/internal.compile_else.php +++ b/libs/sysplugins/internal.compile_else.php @@ -23,8 +23,8 @@ class Smarty_Internal_Compile_Else extends Smarty_Internal_CompileBase { public function compile($args, $compiler) { $this->compiler = $compiler; - $this->_close_tag(array('if', 'elseif')); - $this->_open_tag('else'); + $nesting = $this->_close_tag(array('if', 'elseif')); + $this->_open_tag('else',$nesting); return ''; } diff --git a/libs/sysplugins/internal.compile_elseif.php b/libs/sysplugins/internal.compile_elseif.php index 4e3e83b8..b5ca202b 100644 --- a/libs/sysplugins/internal.compile_elseif.php +++ b/libs/sysplugins/internal.compile_elseif.php @@ -21,15 +21,23 @@ class Smarty_Internal_Compile_ElseIf extends Smarty_Internal_CompileBase { */ public function compile($args, $compiler) { - $this->compiler = $compiler; + $this->compiler = $compiler; $this->required_attributes = array('if condition'); // check and get attributes $_attr = $this->_get_attributes($args); - $this->_close_tag(array('if', 'elseif')); - $this->_open_tag('elseif'); + $nesting = $this->_close_tag(array('if', 'elseif')); - return ''; + if (empty($this->compiler->prefix_code)) { + $this->_open_tag('elseif', $nesting); + return ''; + } else { + $tmp = ''; + foreach ($this->compiler->prefix_code as $code) $tmp .= $code; + $this->compiler->prefix_code = array(); + $this->_open_tag('elseif', $nesting + 1); + return '' . $tmp . ''; + } } } diff --git a/libs/sysplugins/internal.compile_if.php b/libs/sysplugins/internal.compile_if.php index 248396fc..2792e0c9 100644 --- a/libs/sysplugins/internal.compile_if.php +++ b/libs/sysplugins/internal.compile_if.php @@ -26,7 +26,7 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase { // check and get attributes $_attr = $this->_get_attributes($args); - $this->_open_tag('if'); + $this->_open_tag('if',1); if (is_array($args['if condition'])) { $_output = " tpl_vars[".$args['if condition']['var']."])) \$_smarty_tpl->tpl_vars[".$args['if condition']['var']."] = new Smarty_Variable;\n"; $_output .= "if (\$_smarty_tpl->tpl_vars[".$args['if condition']['var']."]->value = ".$args['if condition']['value']."): ?>"; diff --git a/libs/sysplugins/internal.compile_ifclose.php b/libs/sysplugins/internal.compile_ifclose.php index f67c9d40..1ac1fc0f 100644 --- a/libs/sysplugins/internal.compile_ifclose.php +++ b/libs/sysplugins/internal.compile_ifclose.php @@ -23,9 +23,11 @@ class Smarty_Internal_Compile_IfClose extends Smarty_Internal_CompileBase { public function compile($args, $compiler) { $this->compiler = $compiler; - $this->_close_tag(array('if', 'else', 'elseif')); - return ""; + $nesting = $this->_close_tag(array('if', 'else', 'elseif')); + $tmp = ''; + for ($i = 0; $i < $nesting ; $i++) $tmp .= ' endif;'; + return ""; } } -?> +?> diff --git a/libs/sysplugins/internal.compile_print_expression.php b/libs/sysplugins/internal.compile_print_expression.php index 5a3cc3d3..57ed85df 100644 --- a/libs/sysplugins/internal.compile_print_expression.php +++ b/libs/sysplugins/internal.compile_print_expression.php @@ -48,7 +48,11 @@ class Smarty_Internal_Compile_Print_Expression extends Smarty_Internal_CompileBa } else { // display value $this->compiler->has_output = true; - $output = 'smarty->filter_handler->execute(\'variable\', ' . $_attr['value'] . ',' . $_attr['filter'] . ');?>'; + if (isset($this->compiler->smarty->registered_filters['variable'])) { + $output = 'smarty->filter_handler->execute(\'variable\', ' . $_attr['value'] . ',' . $_attr['filter'] . ');?>'; + } else { + $output = ''; + } } return $output; } diff --git a/libs/sysplugins/internal.templateparser.php b/libs/sysplugins/internal.templateparser.php index 382f7035..81c4a4e6 100644 --- a/libs/sysplugins/internal.templateparser.php +++ b/libs/sysplugins/internal.templateparser.php @@ -131,7 +131,7 @@ class Smarty_Internal_Templateparser#line 109 "internal.templateparser.php" $this->cacher = $this->template->cacher_object; $this->compiler->has_variable_string = false; $this->nocache = false; - $this->prefix_code = array(); + $this->compiler->prefix_code = array(); $this->prefix_number = 0; } public static function &instance($new_instance = null) @@ -1982,7 +1982,7 @@ static public $yy_action = array( #line 94 "internal.templateparser.y" function yy_r3(){preg_match('/\s*/',$this->yystack[$this->yyidx + -2]->minor,$s); if ($this->compiler->has_code) { - $tmp =''; foreach ($this->prefix_code as $code) {$tmp.=$code;} $this->prefix_code=array(); + $tmp =''; foreach ($this->compiler->prefix_code as $code) {$tmp.=$code;} $this->compiler->prefix_code=array(); $this->_retvalue = $this->cacher->processNocacheCode($tmp.$s[0].$this->yystack[$this->yyidx + -1]->minor, $this->compiler,$this->nocache,true); } else { $this->_retvalue = $s[0].$this->yystack[$this->yyidx + -1]->minor;} $this->nocache=false; $this->compiler->has_variable_string = false; } #line 1993 "internal.templateparser.php" @@ -2190,13 +2190,13 @@ static public $yy_action = array( function yy_r65(){ $this->_retvalue = $this->yystack[$this->yyidx + -2]->minor.'::'.$this->yystack[$this->yyidx + 0]->minor; } #line 2196 "internal.templateparser.php" #line 314 "internal.templateparser.y" - function yy_r66(){ $this->prefix_number++; $this->prefix_code[] = 'prefix_number.'=$_smarty_tpl->getVariable(\''. $this->yystack[$this->yyidx + -3]->minor .'\')->value;?>'; $this->_retvalue = $this->yystack[$this->yyidx + -6]->minor.'::$_tmp'.$this->prefix_number.'('. $this->yystack[$this->yyidx + -1]->minor .')'; } + function yy_r66(){ $this->prefix_number++; $this->compiler->prefix_code[] = 'prefix_number.'=$_smarty_tpl->getVariable(\''. $this->yystack[$this->yyidx + -3]->minor .'\')->value;?>'; $this->_retvalue = $this->yystack[$this->yyidx + -6]->minor.'::$_tmp'.$this->prefix_number.'('. $this->yystack[$this->yyidx + -1]->minor .')'; } #line 2199 "internal.templateparser.php" #line 316 "internal.templateparser.y" function yy_r67(){ $this->_retvalue = $this->yystack[$this->yyidx + -3]->minor.'::'.$this->yystack[$this->yyidx + -1]->minor.$this->yystack[$this->yyidx + 0]->minor; } #line 2202 "internal.templateparser.php" #line 317 "internal.templateparser.y" - function yy_r68(){ $this->prefix_number++; $this->prefix_code[] = 'prefix_number.'=$_smarty_tpl->getVariable(\''. $this->yystack[$this->yyidx + -4]->minor .'\')->value;?>'; $this->_retvalue = $this->yystack[$this->yyidx + -7]->minor.'::$_tmp'.$this->prefix_number.'('. $this->yystack[$this->yyidx + -2]->minor .')'.$this->yystack[$this->yyidx + 0]->minor; } + function yy_r68(){ $this->prefix_number++; $this->compiler->prefix_code[] = 'prefix_number.'=$_smarty_tpl->getVariable(\''. $this->yystack[$this->yyidx + -4]->minor .'\')->value;?>'; $this->_retvalue = $this->yystack[$this->yyidx + -7]->minor.'::$_tmp'.$this->prefix_number.'('. $this->yystack[$this->yyidx + -2]->minor .')'.$this->yystack[$this->yyidx + 0]->minor; } #line 2205 "internal.templateparser.php" #line 319 "internal.templateparser.y" function yy_r69(){ $this->_retvalue = $this->yystack[$this->yyidx + -2]->minor.'::'.$this->yystack[$this->yyidx + 0]->minor; } @@ -2208,7 +2208,7 @@ static public $yy_action = array( function yy_r71(){ $this->_retvalue = $this->yystack[$this->yyidx + -5]->minor.'::$'.$this->yystack[$this->yyidx + -2]->minor.$this->yystack[$this->yyidx + -1]->minor.$this->yystack[$this->yyidx + 0]->minor; } #line 2214 "internal.templateparser.php" #line 325 "internal.templateparser.y" - function yy_r72(){ $this->prefix_number++; $this->prefix_code[] = ''.$this->yystack[$this->yyidx + -1]->minor.'prefix_number.'=ob_get_clean();?>'; $this->_retvalue = '$_tmp'.$this->prefix_number; } + function yy_r72(){ $this->prefix_number++; $this->compiler->prefix_code[] = ''.$this->yystack[$this->yyidx + -1]->minor.'prefix_number.'=ob_get_clean();?>'; $this->_retvalue = '$_tmp'.$this->prefix_number; } #line 2217 "internal.templateparser.php" #line 334 "internal.templateparser.y" function yy_r73(){if ($this->yystack[$this->yyidx + 0]->minor['var'] == '\'smarty\'') { $this->_retvalue = $this->compiler->compileTag('internal_smarty_var',$this->yystack[$this->yyidx + 0]->minor['index']);} else { @@ -2351,7 +2351,7 @@ static public $yy_action = array( function yy_r125(){$this->_retvalue = '(1 & '.$this->yystack[$this->yyidx + -2]->minor.' / '.$this->yystack[$this->yyidx + 0]->minor.')'; } #line 2357 "internal.templateparser.php" #line 473 "internal.templateparser.y" - function yy_r131(){$this->prefix_number++; $this->prefix_code[] = 'prefix_number.'='.$this->yystack[$this->yyidx + 0]->minor.';?>'; $this->_retvalue = $this->yystack[$this->yyidx + -2]->minor.$this->yystack[$this->yyidx + -1]->minor.'$_tmp'.$this->prefix_number; } + function yy_r131(){$this->prefix_number++; $this->compiler->prefix_code[] = 'prefix_number.'='.$this->yystack[$this->yyidx + 0]->minor.';?>'; $this->_retvalue = $this->yystack[$this->yyidx + -2]->minor.$this->yystack[$this->yyidx + -1]->minor.'$_tmp'.$this->prefix_number; } #line 2360 "internal.templateparser.php" #line 475 "internal.templateparser.y" function yy_r132(){$this->_retvalue = '=='; } @@ -2414,7 +2414,7 @@ static public $yy_action = array( function yy_r155(){preg_match('/\s*/',$this->yystack[$this->yyidx + -2]->minor,$s); $this->_retvalue = $s[0].'".('.$this->yystack[$this->yyidx + -1]->minor.')."'; $this->compiler->has_variable_string = true; } #line 2420 "internal.templateparser.php" #line 509 "internal.templateparser.y" - function yy_r156(){ preg_match('/\s*/',$this->yystack[$this->yyidx + -2]->minor,$s); $this->prefix_number++; $this->prefix_code[] = ''.$this->yystack[$this->yyidx + -1]->minor.'prefix_number.'=ob_get_clean();?>'; $this->_retvalue = $s[0].'".$_tmp'.$this->prefix_number.'."'; $this->compiler->has_variable_string = true; } + function yy_r156(){ preg_match('/\s*/',$this->yystack[$this->yyidx + -2]->minor,$s); $this->prefix_number++; $this->compiler->prefix_code[] = ''.$this->yystack[$this->yyidx + -1]->minor.'prefix_number.'=ob_get_clean();?>'; $this->_retvalue = $s[0].'".$_tmp'.$this->prefix_number.'."'; $this->compiler->has_variable_string = true; } #line 2423 "internal.templateparser.php" #line 510 "internal.templateparser.y" function yy_r157(){$this->_retvalue = '$'.$this->yystack[$this->yyidx + 0]->minor; }