Skip to content

Commit

Permalink
Use (*SKIP)(*F) to avoid useless callback invocations
Browse files Browse the repository at this point in the history
  • Loading branch information
bwoebi committed Nov 7, 2015
1 parent 8b59229 commit 4d10b75
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions lib/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,16 +462,13 @@ public function prepare($query, $data = null) {
$promise = $this->startCommand(function() use ($query) {
$this->query = $query;
$regex = <<<'REGEX'
("|'|`)((?:\\\\|\\\1|(?!\1).)*+)\1|(\?)|:([a-zA-Z_]+)
(["'`])(?:\\(?:\\|\1)|(?!\1).)*+\1(*SKIP)(*F)|(\?)|:([a-zA-Z_]+)
REGEX;

$index = 0;
$query = preg_replace_callback("~$regex~ms", function ($m) use (&$index) {
if (!isset($m[3])) {
return $m[1] . $m[2] . $m[1];
}
if ($m[3] !== "?") {
$this->named[$m[4]][] = $index;
if ($m[2] !== "?") {
$this->named[$m[3]][] = $index;
}
$index++;
return "?";
Expand Down

0 comments on commit 4d10b75

Please sign in to comment.