Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TwigPreLexer: improve performance #1175

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/TwigComponent/src/Twig/TwigPreLexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public function __construct(int $startingLine = 1)

public function preLexComponents(string $input): string
{
if (!str_contains($input, '<twig:')) {
return $input;
}

$this->input = $input;
$this->length = \strlen($input);
$output = '';
Expand Down Expand Up @@ -259,6 +263,10 @@ private function consumeAttributes(string $componentName): string
*/
private function consume(string $string): bool
{
if ($string[0] !== $this->input[$this->position]) {
return false;
}
Copy link
Contributor Author

@gharlan gharlan Oct 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change alone increases the cache:warmup time by 11% (in my project):

Together with the other change, this change is now only relevant for templates using the html component syntax.


$stringLength = \strlen($string);
if (substr($this->input, $this->position, $stringLength) === $string) {
$this->position += $stringLength;
Expand Down
Loading