Skip to content

Commit 101d207

Browse files
committed
feature #1175 TwigPreLexer: improve performance (gharlan)
This PR was merged into the 2.x branch. Discussion ---------- TwigPreLexer: improve performance | Q | A | ------------- | --- | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Tickets | <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT When using the `cache:warmup` command in my symfony project, 25% of the time is used by the TwigPreLexer: <img src="https://github.com/symfony/ux/assets/330436/4539dd1d-d8d2-4633-8c1d-503afe2218be" width=500/> This PR reduces the time of the `cache:warmup` command by 28% in my project (which does not use the html component syntax so far): <img src="https://github.com/symfony/ux/assets/330436/f6df7275-e15a-40c3-ba36-33b099c5c0b1" width=500/> Commits ------- 2568098 TwigPreLexer: improve performance
2 parents 38dc19e + 2568098 commit 101d207

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/TwigComponent/src/Twig/TwigPreLexer.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ public function __construct(int $startingLine = 1)
3434

3535
public function preLexComponents(string $input): string
3636
{
37+
if (!str_contains($input, '<twig:')) {
38+
return $input;
39+
}
40+
3741
$this->input = $input;
3842
$this->length = \strlen($input);
3943
$output = '';
@@ -259,6 +263,10 @@ private function consumeAttributes(string $componentName): string
259263
*/
260264
private function consume(string $string): bool
261265
{
266+
if ($string[0] !== $this->input[$this->position]) {
267+
return false;
268+
}
269+
262270
$stringLength = \strlen($string);
263271
if (substr($this->input, $this->position, $stringLength) === $string) {
264272
$this->position += $stringLength;

0 commit comments

Comments
 (0)