diff --git a/change_log.txt b/change_log.txt index 06be758b..5a7b52fb 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,3 +1,6 @@ +01/07/2010 +- removed call_user_func_array calls for optimization of compiled code when using registered modifiers and plugins + 25/06/2010 - bugfix escaping " when block tags are used within doublequoted strings diff --git a/libs/plugins/function.counter.php b/libs/plugins/function.counter.php index 1f6e1cf7..7ad64807 100644 --- a/libs/plugins/function.counter.php +++ b/libs/plugins/function.counter.php @@ -2,7 +2,7 @@ /** * Smarty plugin * @package Smarty - * @subpackage plugins + * @subpackage PluginsFunction */ diff --git a/libs/plugins/function.cycle.php b/libs/plugins/function.cycle.php index 509584c9..2b616d11 100644 --- a/libs/plugins/function.cycle.php +++ b/libs/plugins/function.cycle.php @@ -2,7 +2,7 @@ /** * Smarty plugin * @package Smarty - * @subpackage plugins + * @subpackage PluginsFunction */ /** diff --git a/libs/plugins/modifier.regex_replace.php b/libs/plugins/modifier.regex_replace.php index 7c6e6b90..16f4c48e 100644 --- a/libs/plugins/modifier.regex_replace.php +++ b/libs/plugins/modifier.regex_replace.php @@ -2,8 +2,8 @@ /** * Smarty plugin * @package Smarty - * @subpackage plugins - */ + * @subpackage PluginsModifier +*/ /** diff --git a/libs/sysplugins/smarty_internal_compile_private_block_plugin.php b/libs/sysplugins/smarty_internal_compile_private_block_plugin.php index 5a9b1140..75df766b 100644 --- a/libs/sysplugins/smarty_internal_compile_private_block_plugin.php +++ b/libs/sysplugins/smarty_internal_compile_private_block_plugin.php @@ -1,25 +1,25 @@ compiler = $compiler; @@ -44,11 +44,7 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi // maybe nocache because of nocache variables or nocache plugin $this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache; // compile code - if (is_array($function)) { - $output = "smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; call_user_func_array(array('{$function[0]}','{$function[1]}'),(array({$_params}, null, \$_smarty_tpl->smarty, &\$_block_repeat, \$_smarty_tpl));while (\$_block_repeat) { ob_start();?>"; - } else { - $output = "smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; {$function}({$_params}, null, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl);while (\$_block_repeat) { ob_start();?>"; - } + $output = "smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; {$function}({$_params}, null, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl);while (\$_block_repeat) { ob_start();?>"; } else { // must endblock be nocache? if ($this->compiler->nocache) { @@ -59,13 +55,9 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi // This tag does create output $this->compiler->has_output = true; // compile code - if (is_array($function)) { - $output = "smarty, &\$_block_repeat, \$_smarty_tpl)); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; - } else { - $output = "smarty, \$_block_repeat, \$_smarty_tpl); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; - } + $output = "smarty, \$_block_repeat, \$_smarty_tpl); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; } - return $output."\n"; + return $output . "\n"; } } diff --git a/libs/sysplugins/smarty_internal_compile_private_function_plugin.php b/libs/sysplugins/smarty_internal_compile_private_function_plugin.php index 80cb1bfa..9abb5829 100644 --- a/libs/sysplugins/smarty_internal_compile_private_function_plugin.php +++ b/libs/sysplugins/smarty_internal_compile_private_function_plugin.php @@ -1,25 +1,25 @@ compiler = $compiler; @@ -41,11 +41,7 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co } $_params = 'array(' . implode(",", $_paramsArray) . ')'; // compile code - if (is_array($function)) { - $output = "smarty,\$_smarty_tpl);?>\n"; - } else { - $output = "smarty,\$_smarty_tpl);?>\n"; - } + $output = "smarty,\$_smarty_tpl);?>\n"; return $output; } } diff --git a/libs/sysplugins/smarty_internal_compile_private_modifier.php b/libs/sysplugins/smarty_internal_compile_private_modifier.php index c4fbfa5e..adc40e0b 100644 --- a/libs/sysplugins/smarty_internal_compile_private_modifier.php +++ b/libs/sysplugins/smarty_internal_compile_private_modifier.php @@ -1,24 +1,24 @@ compiler = $compiler; @@ -30,19 +30,17 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa if (isset($compiler->smarty->registered_plugins['modifier'][$_attr['modifier']])) { $function = $compiler->smarty->registered_plugins['modifier'][$_attr['modifier']][0]; if (!is_array($function)) { - $output = "{$function}({$_attr['params']})"; - } else if (is_object($function[0])) { - $output = 'call_user_func_array($_smarty_tpl->smarty->registered_plugins[\'modifier\'][\'' . $_attr['modifier'] . '\'][0],array(' . $_attr['params'] . '))'; + $output = "{$function}({$_attr['params']})"; } else { - $output = 'call_user_func_array(array(\'' . $function[0] . '\',\'' . $function[1] . '\'),array(' . $_attr['params'] . '))'; + if (is_object($function[0])) { + $output = '$_smarty_tpl->smarty->registered_plugins[\'modifier\'][\'' . $_attr['modifier'] . '\'][0][0]->' . $function[1] . '(' . $_attr['params'] . ')'; + } else { + $output = $function[0] . '::' . $function[1] . '(' . $_attr['params'] . ')'; + } } - // check for plugin modifier + // check for plugin modifier } else if ($function = $this->compiler->getPlugin($_attr['modifier'], 'modifier')) { - if (!is_array($function)) { - $output = "{$function}({$_attr['params']})"; - } else { - $output = 'call_user_func_array(array(\'' . $function[0] . '\',\'' . $function[1] . '\'),array(' . $_attr['params'] . '))'; - } + $output = "{$function}({$_attr['params']})"; // check if trusted PHP function } else if (is_callable($_attr['modifier'])) { // check if modifier allowed @@ -56,4 +54,4 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa } } -?> +?> \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_compile_private_registered_block.php b/libs/sysplugins/smarty_internal_compile_private_registered_block.php index e0e7d87f..f879f715 100644 --- a/libs/sysplugins/smarty_internal_compile_private_registered_block.php +++ b/libs/sysplugins/smarty_internal_compile_private_registered_block.php @@ -48,9 +48,9 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C if (!is_array($function)) { $output = "smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; {$function}({$_params}, null, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl);while (\$_block_repeat) { ob_start();?>"; } else if (is_object($function[0])) { - $output = "smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; call_user_func_array(\$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0],array({$_params}, null, \$_smarty_tpl->smarty, &\$_block_repeat, \$_smarty_tpl));while (\$_block_repeat) { ob_start();?>"; + $output = "smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; \$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0][0]->{$function[1]}({$_params}, null, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl);while (\$_block_repeat) { ob_start();?>"; } else { - $output = "smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; call_user_func_array(array('{$function[0]}','{$function[1]}'),array({$_params}, null, \$_smarty_tpl->smarty, &\$_block_repeat, \$_smarty_tpl));while (\$_block_repeat) { ob_start();?>"; + $output = "smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; {$function[0]}::{$function[1]}({$_params}, null, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl);while (\$_block_repeat) { ob_start();?>"; } } else { // must endblock be nocache? @@ -67,9 +67,9 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C if (!is_array($function)) { $output = "smarty, \$_block_repeat, \$_smarty_tpl); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; } else if (is_object($function[0])) { - $output = "smarty->registered_plugins['block']['{$base_tag}'][0],array({$_params}, \$_block_content, \$_smarty_tpl->smarty, &\$_block_repeat, \$_smarty_tpl)); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; + $output = "smarty->registered_plugins['block']['{$base_tag}'][0][0]->{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; } else { - $output = "smarty, &\$_block_repeat, \$_smarty_tpl)); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; + $output = "smarty, \$_block_repeat, \$_smarty_tpl); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; } } return $output."\n"; diff --git a/libs/sysplugins/smarty_internal_compile_private_registered_function.php b/libs/sysplugins/smarty_internal_compile_private_registered_function.php index e7d2cd6b..bf4e728c 100644 --- a/libs/sysplugins/smarty_internal_compile_private_registered_function.php +++ b/libs/sysplugins/smarty_internal_compile_private_registered_function.php @@ -42,15 +42,14 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna } } $_params = 'array(' . implode(",", $_paramsArray) . ')'; - // compile code $function = $compiler->smarty->registered_plugins['function'][$tag][0]; // compile code if (!is_array($function)) { $output = "smarty,\$_smarty_tpl);?>\n"; } else if (is_object($function[0])) { - $output = "smarty->registered_plugins['function']['{$tag}'][0],{$_params},\$_smarty_tpl->smarty,\$_smarty_tpl);?>\n"; + $output = "smarty->registered_plugins['function']['{$tag}'][0][0]->{$function[1]}({$_params},\$_smarty_tpl->smarty,\$_smarty_tpl);?>\n"; } else { - $output = "smarty,\$_smarty_tpl);?>\n"; + $output = "smarty,\$_smarty_tpl);?>\n"; } return $output; } diff --git a/libs/sysplugins/smarty_internal_parsetree.php b/libs/sysplugins/smarty_internal_parsetree.php index 605fe56b..e0f99f34 100644 --- a/libs/sysplugins/smarty_internal_parsetree.php +++ b/libs/sysplugins/smarty_internal_parsetree.php @@ -1,4 +1,14 @@ smarty->registered_plugins[$type][$tag][1]) { $this->tag_nocache = true; } - return call_user_func_array($this->smarty->registered_plugins[$type][$tag][0], array($args, $this)); + $function = $this->smarty->registered_plugins[$type][$tag][0]; + if (!is_array($function)) { + return $function($args, $this); + } else if (is_object($function[0])) { + return $this->smarty->registered_plugins[$type][$tag][0][0]->$function[1]($args, $this); + } else { + return call_user_func_array($this->smarty->registered_plugins[$type][$tag][0], array($args, $this)); + } } // compile registered function or block function if ($type == 'function' || $type == 'block') { @@ -286,23 +293,6 @@ class Smarty_Internal_TemplateCompilerBase { } return $function; } - /** - * if (isset($this->template->required_plugins_call[$plugin_name][$type])) { - * if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { - * if (isset($this->template->required_plugins['compiled'][$plugin_name])) { - * $this->template->required_plugins['cache'][$plugin_name] = $this->template->required_plugins['compiled'][$plugin_name]; - * } - * } else { - * if (isset($this->template->required_plugins['cache'][$plugin_name])) { - * $this->template->required_plugins['compiled'][$plugin_name] = $this->template->required_plugins['cache'][$plugin_name]; - * } - * } - * if ($type == 'modifier') { - * $this->template->saved_modifier[$plugin_name] = true; - * } - * return $this->template->required_plugins_call[$plugin_name][$type]; - * } - */ // loop through plugin dirs and find the plugin $function = 'smarty_' . $type . '_' . $plugin_name; $found = false; @@ -315,7 +305,6 @@ class Smarty_Internal_TemplateCompilerBase { } } if ($found) { - // if (is_callable($plugin)) { if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { $this->template->required_plugins['nocache'][$plugin_name][$type]['file'] = $file; $this->template->required_plugins['nocache'][$plugin_name][$type]['function'] = $function; @@ -323,16 +312,6 @@ class Smarty_Internal_TemplateCompilerBase { $this->template->required_plugins['compiled'][$plugin_name][$type]['file'] = $file; $this->template->required_plugins['compiled'][$plugin_name][$type]['function'] = $function; } - /** - * $this->template->required_plugins_call[$plugin_name][$type] = $plugin; - * if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { - * $this->template->required_plugins['cache'][$plugin_name]['file'] = $file; - * $this->template->required_plugins['cache'][$plugin_name]['type'] = $type; - * } else { - * $this->template->required_plugins['compiled'][$plugin_name]['file'] = $file; - * $this->template->required_plugins['compiled'][$plugin_name]['type'] = $type; - * } - */ if ($type == 'modifier') { $this->template->saved_modifier[$plugin_name] = true; }