Skip to content

Commit 208ddde

Browse files
committed
Merge branch '4.3.x' into 5.0.x
* 4.3.x: Remove "minimal" dependency setting (#6999) Use latest stable sqlsrv extensions Trigger CI workflow on changes in reusable workflows feat: improve performance of sql parser
2 parents 937e08f + 1f3b6e4 commit 208ddde

File tree

3 files changed

+23
-34
lines changed

3 files changed

+23
-34
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
- "*.x"
77
paths:
88
- .github/workflows/continuous-integration.yml
9+
- .github/workflows/phpunit-*.yml
910
- ci/**
1011
- composer.*
1112
- phpunit.xml.dist
@@ -16,6 +17,7 @@ on:
1617
- "*.x"
1718
paths:
1819
- .github/workflows/continuous-integration.yml
20+
- .github/workflows/phpunit-*.yml
1921
- ci/**
2022
- composer.*
2123
- phpunit.xml.dist

.github/workflows/phpunit-sqlserver.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
uses: shivammathur/setup-php@v2
3838
with:
3939
php-version: ${{ inputs.php-version }}
40-
extensions: ${{ inputs.extension }}-5.10.0beta1
40+
extensions: ${{ inputs.extension }}
4141
coverage: pcov
4242
ini-values: zend.assertions=1
4343
tools: pecl

src/SQL/Parser.php

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,9 @@
99
use Doctrine\DBAL\SQL\Parser\Visitor;
1010

1111
use function array_merge;
12-
use function assert;
13-
use function current;
1412
use function implode;
15-
use function key;
16-
use function next;
1713
use function preg_last_error;
1814
use function preg_match;
19-
use function reset;
2015
use function sprintf;
2116
use function strlen;
2217

@@ -47,6 +42,7 @@ final class Parser
4742
private const OTHER = '[^' . self::SPECIAL_CHARS . ']+';
4843

4944
private readonly string $sqlPattern;
45+
private readonly string $tokenPattern;
5046

5147
public function __construct(bool $mySQLStringEscaping)
5248
{
@@ -71,7 +67,12 @@ public function __construct(bool $mySQLStringEscaping)
7167
self::OTHER,
7268
]);
7369

74-
$this->sqlPattern = sprintf('(%s)', implode('|', $patterns));
70+
$this->sqlPattern = sprintf('(%s)', implode('|', $patterns));
71+
$this->tokenPattern = '~\\G'
72+
. '(?P<named>' . self::NAMED_PARAMETER . ')'
73+
. '|(?P<positional>' . self::POSITIONAL_PARAMETER . ')'
74+
. '|(?P<other>' . $this->sqlPattern . '|' . self::SPECIAL . ')'
75+
. '~s';
7576
}
7677

7778
/**
@@ -81,40 +82,26 @@ public function __construct(bool $mySQLStringEscaping)
8182
*/
8283
public function parse(string $sql, Visitor $visitor): void
8384
{
84-
/** @var array<string,callable> $patterns */
85-
$patterns = [
86-
self::NAMED_PARAMETER => static function (string $sql) use ($visitor): void {
87-
$visitor->acceptNamedParameter($sql);
88-
},
89-
self::POSITIONAL_PARAMETER => static function (string $sql) use ($visitor): void {
90-
$visitor->acceptPositionalParameter($sql);
91-
},
92-
$this->sqlPattern => static function (string $sql) use ($visitor): void {
93-
$visitor->acceptOther($sql);
94-
},
95-
self::SPECIAL => static function (string $sql) use ($visitor): void {
96-
$visitor->acceptOther($sql);
97-
},
98-
];
99-
10085
$offset = 0;
101-
102-
while (($handler = current($patterns)) !== false) {
103-
if (preg_match('~\G' . key($patterns) . '~s', $sql, $matches, 0, $offset) === 1) {
104-
$handler($matches[0]);
105-
reset($patterns);
106-
107-
$offset += strlen($matches[0]);
86+
$length = strlen($sql);
87+
while ($offset < $length) {
88+
if (preg_match($this->tokenPattern, $sql, $matches, 0, $offset) === 1) {
89+
$match = $matches[0];
90+
if ($matches['named'] !== '') {
91+
$visitor->acceptNamedParameter($match);
92+
} elseif ($matches['positional'] !== '') {
93+
$visitor->acceptPositionalParameter($match);
94+
} else {
95+
$visitor->acceptOther($match);
96+
}
97+
98+
$offset += strlen($match);
10899
} elseif (preg_last_error() !== PREG_NO_ERROR) {
109100
// @codeCoverageIgnoreStart
110101
throw RegularExpressionError::new();
111102
// @codeCoverageIgnoreEnd
112-
} else {
113-
next($patterns);
114103
}
115104
}
116-
117-
assert($offset === strlen($sql));
118105
}
119106

120107
private function getMySQLStringLiteralPattern(string $delimiter): string

0 commit comments

Comments
 (0)