Skip to content

Commit 101f814

Browse files
authored
Improve performance of SqlParser::getNextPlaceholder() method (#482)
1 parent e869754 commit 101f814

2 files changed

Lines changed: 7 additions & 14 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## 2.0.2 under development
44

5-
- no changes in this release.
5+
- Enh #482: Improve performance of `SqlParser::getNextPlaceholder()` method (@Tigrov)
66

77
## 2.0.1 February 07, 2026
88

‎src/SqlParser.php‎

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
final class SqlParser extends AbstractSqlParser
1010
{
11+
/** @var string Identifier characters, equivalent to `[$\w]` in regular expressions */
12+
private const IDENTIFIER_CHARS = '$' . self::WORD_CHARS;
13+
1114
public function getNextPlaceholder(?int &$position = null): ?string
1215
{
1316
$result = null;
@@ -67,21 +70,11 @@ private function skipQuotedWithDollar(): void
6770
}
6871

6972
/**
70-
* Skips an identifier. Equals to `[$\w]+` in regular expressions.
73+
* Skips an identifier. Equivalent to `[$\w]*` in regular expressions.
7174
*/
7275
private function skipIdentifier(): void
7376
{
74-
$continue = true;
75-
76-
while ($continue && $this->position < $this->length) {
77-
match ($this->sql[$this->position]) {
78-
'$', '_', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
79-
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
80-
'v', 'w', 'x', 'y', 'z',
81-
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
82-
'V', 'W', 'X', 'Y', 'Z' => ++$this->position,
83-
default => $continue = false,
84-
};
85-
}
77+
$length = strspn($this->sql, self::IDENTIFIER_CHARS, $this->position);
78+
$this->position += $length;
8679
}
8780
}

0 commit comments

Comments
 (0)