From 21bf6c612f6da89396a1941adf184a78360645ed Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 8 Nov 2011 18:36:26 +0100 Subject: [PATCH] Optimizing TemplateScriptingCompiler: Output Buffering Shortening ob_get_contents(); ob_end_clean(); to ob_get_clean(); > ob_get_clean() essentially executes both ob_get_contents() and ob_end_clean(). --- .../system/template/TemplateScriptingCompiler.class.php | 8 +++----- .../template/plugin/IconCompilerTemplatePlugin.class.php | 3 +-- .../template/plugin/LangCompilerTemplatePlugin.class.php | 3 +-- .../plugin/StaticlangTemplatePluginCompiler.class.php | 3 +-- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/wcfsetup/install/files/lib/system/template/TemplateScriptingCompiler.class.php b/wcfsetup/install/files/lib/system/template/TemplateScriptingCompiler.class.php index 1e32b2f283..4cda9ff611 100644 --- a/wcfsetup/install/files/lib/system/template/TemplateScriptingCompiler.class.php +++ b/wcfsetup/install/files/lib/system/template/TemplateScriptingCompiler.class.php @@ -457,9 +457,7 @@ class TemplateScriptingCompiler { } else { $this->popTag($tagCommand); - $phpCode = "pluginObjects['".$className."']->execute(\$this->tagStack[count(\$this->tagStack) - 1][1], \$blockContent, \$this); }\n"; + $phpCode = "pluginObjects['".$className."']->execute(\$this->tagStack[count(\$this->tagStack) - 1][1], ob_get_clean(), \$this); }\n"; $phpCode .= "array_pop(\$this->tagStack);\n"; $phpCode .= "unset(\$blockContent, \$blockRepeat); ?>"; } @@ -545,7 +543,7 @@ class TemplateScriptingCompiler { else { $capture = array_pop($this->captureStack); $phpCode = "v['tpl']['capture'][".$capture['name']."] = ob_get_contents();\nob_end_clean();\n"; + $phpCode .= "\$this->v['tpl']['capture'][".$capture['name']."] = ob_get_clean();\n"; if (!empty($capture['variable'])) $phpCode .= "\$this->".($capture['append'] ? 'append' : 'assign')."(".$capture['variable'].", \$this->v['tpl']['capture'][".$capture['name']."]);\n"; $phpCode .= "?>"; return $phpCode; @@ -733,7 +731,7 @@ class TemplateScriptingCompiler { $phpCode .= '$this->includeTemplate('.$file.', array('.$argString.'), ('.$sandbox.' ? 1 : 0), $this->v[\'__PACKAGE_ID\']);'."\n"; if ($assignVar !== false) { - $phpCode .= '$this->'.($append ? 'append' : 'assign').'('.$assignVar.', ob_get_contents()); ob_end_clean();'."\n"; + $phpCode .= '$this->'.($append ? 'append' : 'assign').'('.$assignVar.', ob_get_clean());'."\n"; } $phpCode .= "\$this->v['tpl']['template'] = \$outerTemplateName".$hash.";\n"; diff --git a/wcfsetup/install/files/lib/system/template/plugin/IconCompilerTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/IconCompilerTemplatePlugin.class.php index ed999feffa..53ef754ad6 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/IconCompilerTemplatePlugin.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/IconCompilerTemplatePlugin.class.php @@ -51,7 +51,6 @@ class IconCompilerTemplatePlugin implements ICompilerTemplatePlugin { */ public function executeEnd(TemplateScriptingCompiler $compiler) { $compiler->popTag('icon'); - $hash = StringUtil::getRandomID(); - return "getStyle()->getIconPath(\$_icon".$hash.", '".$this->size."'); ?>"; + return "getStyle()->getIconPath(ob_get_clean(), '".$this->size."'); ?>"; } } diff --git a/wcfsetup/install/files/lib/system/template/plugin/LangCompilerTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/LangCompilerTemplatePlugin.class.php index 8ec0d31288..3715d5dab5 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/LangCompilerTemplatePlugin.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/LangCompilerTemplatePlugin.class.php @@ -38,7 +38,6 @@ class LangCompilerTemplatePlugin implements ICompilerTemplatePlugin { */ public function executeEnd(TemplateScriptingCompiler $compiler) { $compiler->popTag('lang'); - $hash = StringUtil::getRandomID(); - return "getDynamicVariable(\$_lang".$hash.", \$this->tagStack[count(\$this->tagStack) - 1][1], (isset(\$this->tagStack[count(\$this->tagStack) - 1][1]['__optional']) ? \$this->tagStack[count(\$this->tagStack) - 1][1]['__optional'] : false)); array_pop(\$this->tagStack); ?>"; + return "getDynamicVariable(ob_get_clean(), \$this->tagStack[count(\$this->tagStack) - 1][1], (isset(\$this->tagStack[count(\$this->tagStack) - 1][1]['__optional']) ? \$this->tagStack[count(\$this->tagStack) - 1][1]['__optional'] : false)); array_pop(\$this->tagStack); ?>"; } } diff --git a/wcfsetup/install/files/lib/system/template/plugin/StaticlangTemplatePluginCompiler.class.php b/wcfsetup/install/files/lib/system/template/plugin/StaticlangTemplatePluginCompiler.class.php index 11d44a77da..973ba66972 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/StaticlangTemplatePluginCompiler.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/StaticlangTemplatePluginCompiler.class.php @@ -31,7 +31,6 @@ class StaticlangCompilerTemplatePlugin implements ICompilerTemplatePlugin { */ public function executeEnd(TemplateScriptingCompiler $compiler) { $compiler->popTag('staticlang'); - $hash = StringUtil::getRandomID(); - return "get(\$_lang".$hash."); ?>"; + return "get(ob_get_clean()); ?>"; } } -- 2.20.1