Skip to content

Commit ea17178

Browse files
rzv-metaylorotwell
andauthored
[12.x] perf: Optimize BladeCompiler (#55703)
* Speed up `getOpenAndClosingPhpTokens()` up to 30x * add empty line before return statement * Update BladeCompiler.php --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent f201b8e commit ea17178

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/Illuminate/View/Compilers/BladeCompiler.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,15 @@ protected function appendFilePath($contents)
232232
*/
233233
protected function getOpenAndClosingPhpTokens($contents)
234234
{
235-
return (new Collection(token_get_all($contents)))
236-
->pluck(0)
237-
->filter(function ($token) {
238-
return in_array($token, [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO, T_CLOSE_TAG]);
239-
});
235+
$tokens = [];
236+
237+
foreach (token_get_all($contents) as $token) {
238+
if ($token[0] === T_OPEN_TAG || $token[0] === T_OPEN_TAG_WITH_ECHO || $token[0] === T_CLOSE_TAG) {
239+
$tokens[] = $token[0];
240+
}
241+
}
242+
243+
return new Collection($tokens);
240244
}
241245

242246
/**

0 commit comments

Comments
 (0)