Skip to content

Commit

Permalink
[11.x] Blade Component Loop Speed Improvement (#51158)
Browse files Browse the repository at this point in the history
* Blade Component Loop Speed Improvement

* Corrected tests

* formatting

* remove test

* Updated tests

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
lonnylot and taylorotwell authored Apr 22, 2024
1 parent 7042fec commit 2b1ad99
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/Illuminate/View/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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]
);
}

/**
Expand Down Expand Up @@ -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 = [];
}

/**
Expand Down

0 comments on commit 2b1ad99

Please sign in to comment.