Skip to content

Commit 2b1ad99

Browse files
[11.x] Blade Component Loop Speed Improvement (#51158)
* Blade Component Loop Speed Improvement * Corrected tests * formatting * remove test * Updated tests --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 7042fec commit 2b1ad99

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/Illuminate/View/Factory.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,20 @@ class Factory implements FactoryContract
9090
*/
9191
protected $renderedOnce = [];
9292

93+
/**
94+
* The cached array of engines for paths.
95+
*
96+
* @var array
97+
*/
98+
protected $pathEngineCache = [];
99+
100+
/**
101+
* The cache of normalized names for views.
102+
*
103+
* @var array
104+
*/
105+
protected $normalizedNameCache = [];
106+
93107
/**
94108
* Create a new view factory instance.
95109
*
@@ -247,7 +261,7 @@ public function renderEach($view, $data, $iterator, $empty = 'raw|')
247261
*/
248262
protected function normalizeName($name)
249263
{
250-
return ViewName::normalize($name);
264+
return $this->normalizedNames[$name] ??= ViewName::normalize($name);
251265
}
252266

253267
/**
@@ -301,13 +315,17 @@ public function exists($view)
301315
*/
302316
public function getEngineFromPath($path)
303317
{
318+
if (isset($this->pathEngineCache[$path])) {
319+
return $this->engines->resolve($this->pathEngineCache[$path]);
320+
}
321+
304322
if (! $extension = $this->getExtension($path)) {
305323
throw new InvalidArgumentException("Unrecognized extension in file: {$path}.");
306324
}
307325

308-
$engine = $this->extensions[$extension];
309-
310-
return $this->engines->resolve($engine);
326+
return $this->engines->resolve(
327+
$this->pathEngineCache[$path] = $this->extensions[$extension]
328+
);
311329
}
312330

313331
/**
@@ -467,6 +485,8 @@ public function addExtension($extension, $engine, $resolver = null)
467485
unset($this->extensions[$extension]);
468486

469487
$this->extensions = array_merge([$extension => $engine], $this->extensions);
488+
489+
$this->pathEngineCache = [];
470490
}
471491

472492
/**

0 commit comments

Comments
 (0)