mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-17 10:30:50 +00:00
Avoid allocating a normalized copy when counting newlines without carriage returns
This commit is contained in:
+4
-3
@@ -531,9 +531,10 @@ class Lexer
|
||||
|
||||
private function moveCursor($text): void
|
||||
{
|
||||
$length = \strlen($text);
|
||||
$this->cursor += $length;
|
||||
$this->lineno += substr_count($this->normalizeNewlines($text), "\n");
|
||||
$this->cursor += \strlen($text);
|
||||
// count "\r\n" and "\r" as a single newline without allocating a
|
||||
// normalized copy when the chunk has no carriage return (common case)
|
||||
$this->lineno += str_contains($text, "\r") ? substr_count($this->normalizeNewlines($text), "\n") : substr_count($text, "\n");
|
||||
}
|
||||
|
||||
private function normalizeNewlines(string $text): string
|
||||
|
||||
Reference in New Issue
Block a user