@@ -90,6 +90,20 @@ class Factory implements FactoryContract
90
90
*/
91
91
protected $ renderedOnce = [];
92
92
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
+
93
107
/**
94
108
* Create a new view factory instance.
95
109
*
@@ -247,7 +261,7 @@ public function renderEach($view, $data, $iterator, $empty = 'raw|')
247
261
*/
248
262
protected function normalizeName ($ name )
249
263
{
250
- return ViewName::normalize ($ name );
264
+ return $ this -> normalizedNames [ $ name ] ??= ViewName::normalize ($ name );
251
265
}
252
266
253
267
/**
@@ -301,13 +315,17 @@ public function exists($view)
301
315
*/
302
316
public function getEngineFromPath ($ path )
303
317
{
318
+ if (isset ($ this ->pathEngineCache [$ path ])) {
319
+ return $ this ->engines ->resolve ($ this ->pathEngineCache [$ path ]);
320
+ }
321
+
304
322
if (! $ extension = $ this ->getExtension ($ path )) {
305
323
throw new InvalidArgumentException ("Unrecognized extension in file: {$ path }. " );
306
324
}
307
325
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
+ );
311
329
}
312
330
313
331
/**
@@ -467,6 +485,8 @@ public function addExtension($extension, $engine, $resolver = null)
467
485
unset($ this ->extensions [$ extension ]);
468
486
469
487
$ this ->extensions = array_merge ([$ extension => $ engine ], $ this ->extensions );
488
+
489
+ $ this ->pathEngineCache = [];
470
490
}
471
491
472
492
/**
0 commit comments