From db444586562ab7291a542f96ed7a7386df8f3fc3 Mon Sep 17 00:00:00 2001 From: KoKsPfLaNzE Date: Wed, 20 Nov 2019 21:44:42 +0100 Subject: [PATCH] better stackLoader cache --- src/Twig/StackLoader.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Twig/StackLoader.php b/src/Twig/StackLoader.php index 064f199..6165bc2 100644 --- a/src/Twig/StackLoader.php +++ b/src/Twig/StackLoader.php @@ -67,6 +67,12 @@ protected function findTemplate(string $name, bool $throw = true): ?string // normalize name $name = preg_replace('#/{2,}#', '/', strtr($name, '\\', '/')); + // Ensure we have the expected file extension + $defaultSuffix = $this->getDefaultSuffix(); + if (pathinfo($name, PATHINFO_EXTENSION) != $defaultSuffix) { + $name .= '.' . $defaultSuffix; + } + if (isset($this->cache[$name])) { return $this->cache[$name]; } @@ -78,12 +84,6 @@ protected function findTemplate(string $name, bool $throw = true): ?string throw new Error\LoaderError($this->errorCache[$name]); } - // Ensure we have the expected file extension - $defaultSuffix = $this->getDefaultSuffix(); - if (pathinfo($name, PATHINFO_EXTENSION) != $defaultSuffix) { - $name .= '.' . $defaultSuffix; - } - $this->validateName($name); $namespace = '__main__';