From 648cd688cac37f709790a64db6b234987cbf24aa Mon Sep 17 00:00:00 2001 From: toxyy Date: Sat, 9 Dec 2023 13:19:13 -0500 Subject: [PATCH] [ticket/15214] Move if statement to a better place Putting this here will have the loop run the same amount of times as default. Without this, the loop runs too many extra times. PHPBB3-15214 --- phpBB/phpbb/template/twig/node/event.php | 52 ++++++++++++------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/phpBB/phpbb/template/twig/node/event.php b/phpBB/phpbb/template/twig/node/event.php index 265c609fbc..dfb89f1dc9 100644 --- a/phpBB/phpbb/template/twig/node/event.php +++ b/phpBB/phpbb/template/twig/node/event.php @@ -51,9 +51,12 @@ class event extends \Twig\Node\Node // Group and sort extension template events in according to their priority (0 by default if not set) foreach ($this->environment->get_phpbb_extensions() as $ext_namespace => $ext_path) { - $ext_namespace = str_replace('/', '_', $ext_namespace); - $priority_key = $this->template_event_priority_array[$ext_namespace][$location] ?? 0; - $template_events[$priority_key][] = $ext_namespace; + if ($this->environment->isDebug() || $this->environment->getLoader()->exists('@' . $ext_namespace . '/' . $location . '.html')) + { + $ext_namespace = str_replace('/', '_', $ext_namespace); + $priority_key = $this->template_event_priority_array[$ext_namespace][$location] ?? 0; + $template_events[$priority_key][] = $ext_namespace; + } } krsort($template_events); @@ -61,33 +64,30 @@ class event extends \Twig\Node\Node { foreach ($events as $ext_namespace) { - if ($this->environment->isDebug() || $this->environment->getLoader()->exists('@' . $ext_namespace . '/' . $location . '.html')) + if ($this->environment->isDebug()) { - if ($this->environment->isDebug()) - { - // If debug mode is enabled, lets check for new/removed EVENT - // templates on page load rather than at compile. This is - // slower, but makes developing extensions easier (no need to - // purge the cache when a new event template file is added) - $compiler - ->write("if (\$this->env->getLoader()->exists('@{$ext_namespace}/{$location}.html')) {\n") - ->indent(); - } - + // If debug mode is enabled, lets check for new/removed EVENT + // templates on page load rather than at compile. This is + // slower, but makes developing extensions easier (no need to + // purge the cache when a new event template file is added) $compiler - ->write("\$previous_look_up_order = \$this->env->getNamespaceLookUpOrder();\n") + ->write("if (\$this->env->getLoader()->exists('@{$ext_namespace}/{$location}.html')) {\n") + ->indent(); + } - // We set the namespace lookup order to be this extension first, then the main path - ->write("\$this->env->setNamespaceLookUpOrder(array('{$ext_namespace}', '__main__'));\n") - ->write("\$this->env->loadTemplate('@{$ext_namespace}/{$location}.html')->display(\$context);\n") - ->write("\$this->env->setNamespaceLookUpOrder(\$previous_look_up_order);\n"); + $compiler + ->write("\$previous_look_up_order = \$this->env->getNamespaceLookUpOrder();\n") - if ($this->environment->isDebug()) - { - $compiler - ->outdent() - ->write("}\n\n"); - } + // We set the namespace lookup order to be this extension first, then the main path + ->write("\$this->env->setNamespaceLookUpOrder(array('{$ext_namespace}', '__main__'));\n") + ->write("\$this->env->loadTemplate('@{$ext_namespace}/{$location}.html')->display(\$context);\n") + ->write("\$this->env->setNamespaceLookUpOrder(\$previous_look_up_order);\n"); + + if ($this->environment->isDebug()) + { + $compiler + ->outdent() + ->write("}\n\n"); } } }