mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-30 12:06:56 +00:00
Optimize Environment::resolveTemplate() to be much faster when template overrides do not exist
This commit is contained in:
committed by
Fabien Potencier
parent
a41a6cce62
commit
695423e14e
+7
-6
@@ -501,6 +501,7 @@ class Environment
|
||||
$names = [$names];
|
||||
}
|
||||
|
||||
$count = \count($names);
|
||||
foreach ($names as $name) {
|
||||
if ($name instanceof Template) {
|
||||
return $name;
|
||||
@@ -509,13 +510,13 @@ class Environment
|
||||
return $name;
|
||||
}
|
||||
|
||||
try {
|
||||
return $this->loadTemplate($name);
|
||||
} catch (LoaderError $e) {
|
||||
if (1 === \count($names)) {
|
||||
throw $e;
|
||||
}
|
||||
// Optimization: Avoid throwing an exception when it would be ignored anyway.
|
||||
if (1 !== $count && !$this->getLoader()->exists($name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Throws LoaderError: Unable to find template "%s".
|
||||
return $this->loadTemplate($name);
|
||||
}
|
||||
|
||||
throw new LoaderError(sprintf('Unable to find one of the following templates: "%s".', implode('", "', $names)));
|
||||
|
||||
Reference in New Issue
Block a user