Optimizing TemplateScriptingCompiler: Output Buffering
authorTim Düsterhus <timwolla@arcor.de>
Tue, 8 Nov 2011 17:36:26 +0000 (18:36 +0100)
committerTim Düsterhus <timwolla@arcor.de>
Tue, 8 Nov 2011 19:02:15 +0000 (20:02 +0100)
Shortening ob_get_contents(); ob_end_clean(); to ob_get_clean();
> ob_get_clean() essentially executes both ob_get_contents() and ob_end_clean().

wcfsetup/install/files/lib/system/template/TemplateScriptingCompiler.class.php
wcfsetup/install/files/lib/system/template/plugin/IconCompilerTemplatePlugin.class.php
wcfsetup/install/files/lib/system/template/plugin/LangCompilerTemplatePlugin.class.php
wcfsetup/install/files/lib/system/template/plugin/StaticlangTemplatePluginCompiler.class.php

index 1e32b2f28334ef0e47d2e72c8a072b467c93da2f..4cda9ff611dac8dd30d7bc501688f2b392b02df6 100644 (file)
@@ -457,9 +457,7 @@ class TemplateScriptingCompiler {
                }
                else {
                        $this->popTag($tagCommand);
-                       $phpCode = "<?php \$blockContent = ob_get_contents();\n";
-                       $phpCode .= "ob_end_clean();\n";
-                       $phpCode .= "echo \$this->pluginObjects['".$className."']->execute(\$this->tagStack[count(\$this->tagStack) - 1][1], \$blockContent, \$this); }\n";
+                       $phpCode = "<?php echo \$this->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 = "<?php\n";
-                       $phpCode .= "\$this->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";
index ed999feffae77bf87dfbaa9e4389b48b9d481cb6..53ef754ad6eb4bfb572a2216b476b38e829bb6b4 100644 (file)
@@ -51,7 +51,6 @@ class IconCompilerTemplatePlugin implements ICompilerTemplatePlugin {
         */
        public function executeEnd(TemplateScriptingCompiler $compiler) {
                $compiler->popTag('icon');
-               $hash = StringUtil::getRandomID();
-               return "<?php \$_icon".$hash." = ob_get_contents(); ob_end_clean(); echo wcf\system\style\StyleHandler::getInstance()->getStyle()->getIconPath(\$_icon".$hash.", '".$this->size."'); ?>";
+               return "<?php echo wcf\system\style\StyleHandler::getInstance()->getStyle()->getIconPath(ob_get_clean(), '".$this->size."'); ?>";
        }
 }
index 8ec0d31288f3756caf6db191f146dfafc28be210..3715d5dab5a4e739a9015435fb3d4d50ac15741a 100644 (file)
@@ -38,7 +38,6 @@ class LangCompilerTemplatePlugin implements ICompilerTemplatePlugin {
         */
        public function executeEnd(TemplateScriptingCompiler $compiler) {
                $compiler->popTag('lang');
-               $hash = StringUtil::getRandomID();
-               return "<?php \$_lang".$hash." = ob_get_contents(); ob_end_clean(); echo wcf\system\WCF::getLanguage()->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 "<?php echo wcf\system\WCF::getLanguage()->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); ?>";
        }
 }
index 11d44a77dab3b7661cc8e71b7b0da432c7baadf2..973ba66972c6432a1a73234e407b3e7d9d32c1fb 100644 (file)
@@ -31,7 +31,6 @@ class StaticlangCompilerTemplatePlugin implements ICompilerTemplatePlugin {
         */
        public function executeEnd(TemplateScriptingCompiler $compiler) {
                $compiler->popTag('staticlang');
-               $hash = StringUtil::getRandomID();
-               return "<?php \$_lang".$hash." = ob_get_contents(); ob_end_clean(); echo \wcf\system\WCF::getLanguage()->get(\$_lang".$hash."); ?>";
+               return "<?php echo \wcf\system\WCF::getLanguage()->get(ob_get_clean()); ?>";
        }
 }