Skip to content

Commit 7880563

Browse files
committed
Micro-optimization
strtr() is faster for single-character replacements.
1 parent 8bbb0ea commit 7880563

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

system/Database/BaseBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ protected function whereHaving(string $qbKey, $key, $value = null, string $type
670670

671671
if ($v instanceof Closure) {
672672
$builder = $this->cleanClone();
673-
$v = ' (' . str_replace("\n", ' ', $v($builder)->getCompiledSelect()) . ')';
673+
$v = ' (' . strtr($v($builder)->getCompiledSelect(), "\n", ' ') . ')';
674674
} else {
675675
$bind = $this->setBind($k, $v, $escape);
676676
$v = " :{$bind}:";
@@ -842,7 +842,7 @@ protected function _whereIn(?string $key = null, $values = null, bool $not = fal
842842

843843
if ($values instanceof Closure) {
844844
$builder = $this->cleanClone();
845-
$ok = str_replace("\n", ' ', $values($builder)->getCompiledSelect());
845+
$ok = strtr($values($builder)->getCompiledSelect(), "\n", ' ');
846846
} else {
847847
$whereIn = array_values($values);
848848
$ok = $this->setBind($ok, $whereIn, $escape);

0 commit comments

Comments
 (0)