diff --git a/CHANGELOG.md b/CHANGELOG.md index e0961bd27..2ccb009bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 2.0.2 under development -- no changes in this release. +- Enh #482: Improve performance of `SqlParser::getNextPlaceholder()` method (@Tigrov) ## 2.0.1 February 07, 2026 diff --git a/src/SqlParser.php b/src/SqlParser.php index 8bc311493..79eab4a5c 100644 --- a/src/SqlParser.php +++ b/src/SqlParser.php @@ -8,6 +8,9 @@ final class SqlParser extends AbstractSqlParser { + /** @var string Identifier characters, equivalent to `[$\w]` in regular expressions */ + private const IDENTIFIER_CHARS = '$' . self::WORD_CHARS; + public function getNextPlaceholder(?int &$position = null): ?string { $result = null; @@ -67,21 +70,11 @@ private function skipQuotedWithDollar(): void } /** - * Skips an identifier. Equals to `[$\w]+` in regular expressions. + * Skips an identifier. Equivalent to `[$\w]*` in regular expressions. */ private function skipIdentifier(): void { - $continue = true; - - while ($continue && $this->position < $this->length) { - match ($this->sql[$this->position]) { - '$', '_', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', - 'v', 'w', 'x', 'y', 'z', - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', - 'V', 'W', 'X', 'Y', 'Z' => ++$this->position, - default => $continue = false, - }; - } + $length = strspn($this->sql, self::IDENTIFIER_CHARS, $this->position); + $this->position += $length; } }