diff --git a/src/Illuminate/View/Factory.php b/src/Illuminate/View/Factory.php index 7ca8f94b7a21..f6ec7f7db079 100755 --- a/src/Illuminate/View/Factory.php +++ b/src/Illuminate/View/Factory.php @@ -90,6 +90,20 @@ class Factory implements FactoryContract */ protected $renderedOnce = []; + /** + * The cached array of engines for paths. + * + * @var array + */ + protected $pathEngineCache = []; + + /** + * The cache of normalized names for views. + * + * @var array + */ + protected $normalizedNameCache = []; + /** * Create a new view factory instance. * @@ -247,7 +261,7 @@ public function renderEach($view, $data, $iterator, $empty = 'raw|') */ protected function normalizeName($name) { - return ViewName::normalize($name); + return $this->normalizedNames[$name] ??= ViewName::normalize($name); } /** @@ -301,13 +315,17 @@ public function exists($view) */ public function getEngineFromPath($path) { + if (isset($this->pathEngineCache[$path])) { + return $this->engines->resolve($this->pathEngineCache[$path]); + } + if (! $extension = $this->getExtension($path)) { throw new InvalidArgumentException("Unrecognized extension in file: {$path}."); } - $engine = $this->extensions[$extension]; - - return $this->engines->resolve($engine); + return $this->engines->resolve( + $this->pathEngineCache[$path] = $this->extensions[$extension] + ); } /** @@ -467,6 +485,8 @@ public function addExtension($extension, $engine, $resolver = null) unset($this->extensions[$extension]); $this->extensions = array_merge([$extension => $engine], $this->extensions); + + $this->pathEngineCache = []; } /**