Skip to content

Commit

Permalink
Move count() outside of the loop
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
nijel committed Feb 7, 2017
1 parent 2effa37 commit 6f828ee
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/Components/CaseExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,21 +211,17 @@ public static function build($component, array $options = array())
if (isset($component->value)) {
// Syntax type 0
$ret .= $component->value . ' ';
for (
$i = 0;
$i < count($component->compare_values) && $i < count($component->results);
++$i
) {
$val_cnt = count($component->compare_values);
$res_cnt = count($component->results);
for ($i = 0; $i < $val_cnt && $i < $res_cnt; ++$i) {
$ret .= 'WHEN ' . $component->compare_values[$i] . ' ';
$ret .= 'THEN ' . $component->results[$i] . ' ';
}
} else {
// Syntax type 1
for (
$i = 0;
$i < count($component->conditions) && $i < count($component->results);
++$i
) {
$val_cnt = count($component->conditions);
$res_cnt = count($component->results);
for ($i = 0; $i < $val_cnt && $i < $res_cnt; ++$i) {
$ret .= 'WHEN ' . Condition::build($component->conditions[$i]) . ' ';
$ret .= 'THEN ' . $component->results[$i] . ' ';
}
Expand Down

0 comments on commit 6f828ee

Please sign in to comment.