Skip to content

Commit 4ef0cd9

Browse files
committed
Use str_replace() instead of strtr()
strtr() is purposed for single-character replacements, and less performant when used otherwise.
1 parent b30a75d commit 4ef0cd9

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

system/Database/Query.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ protected function compileBinds()
309309
*/
310310
protected function matchNamedBinds(string $sql, array $binds): string
311311
{
312-
$replacers = [];
312+
$replacersFrom = [];
313+
$replacersTo = [];
313314

314315
foreach ($binds as $placeholder => $value) {
315316
// $value[1] contains the boolean whether should be escaped or not
@@ -322,10 +323,11 @@ protected function matchNamedBinds(string $sql, array $binds): string
322323
$escapedValue = '(' . implode(',', $escapedValue) . ')';
323324
}
324325

325-
$replacers[":{$placeholder}:"] = $escapedValue;
326+
$replacersFrom[] = ":{$placeholder}:"
327+
$replacersTo[] = $escapedValue;
326328
}
327329

328-
return strtr($sql, $replacers);
330+
return str_replace($replacersFrom, $replacersTo, $sql);
329331
}
330332

331333
/**

0 commit comments

Comments
 (0)