Skip to content

Commit

Permalink
Optimize foreach loops:
Browse files Browse the repository at this point in the history
  • Loading branch information
timw4mail committed May 14, 2012
1 parent bf3b072 commit f555b17
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion classes/db_pdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function prepare_query($sql, $data)
}

// Bind the parameters
foreach($data as $k => $value)
foreach($data as $k => &$value)
{
if(is_numeric($k))
{
Expand Down
24 changes: 12 additions & 12 deletions classes/query_builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public function select($fields)
$fields_array = array_map('trim', $fields_array);

// Split on 'As'
foreach ($fields_array as $key => $field)
foreach ($fields_array as $key => &$field)
{
if (stripos($field, 'as') !== FALSE)
{
Expand Down Expand Up @@ -512,7 +512,7 @@ private function _having($key, $val=array(), $conj='AND')
$where = $this->_where($key, $val);

// Create key/value placeholders
foreach($where as $f => $val)
foreach($where as $f => &$val)
{
// Split each key by spaces, in case there
// is an operator such as >, <, !=, etc.
Expand Down Expand Up @@ -585,7 +585,7 @@ private function _where($key, $val=array())
// Array or object, loop through and add to the where array
elseif ( ! is_scalar($key))
{
foreach($key as $k => $v)
foreach($key as $k => &$v)
{
$where[$k] = $v;
$this->values[] = $v;
Expand All @@ -610,7 +610,7 @@ private function _where_string($key, $val=array(), $conj='AND')
$where = $this->_where($key, $val);

// Create key/value placeholders
foreach($where as $f => $val)
foreach($where as $f => &$val)
{
// Split each key by spaces, in case there
// is an operator such as >, <, !=, etc.
Expand Down Expand Up @@ -648,7 +648,7 @@ private function _where_in($key, $val=array(), $in='IN', $conj='AND')
$key = $this->quote_ident($key);
$params = array_fill(0, count($val), '?');

foreach($val as $v)
foreach($val as &$v)
{
$this->values[] = $v;
}
Expand Down Expand Up @@ -772,7 +772,7 @@ public function set($key, $val = NULL)
// Object or array
elseif ( ! is_scalar($key))
{
foreach($key as $k => $v)
foreach($key as $k => &$v)
{
$this->set_array_keys[] = $k;
$this->values[] = $v;
Expand Down Expand Up @@ -869,7 +869,7 @@ public function order_by($field, $type="")
$order_clauses = array();

// Flatten key/val pairs into an array of space-separated pairs
foreach($this->order_array as $k => $v)
foreach($this->order_array as $k => &$v)
{
$order_clauses[] = $k . ' ' . strtoupper($v);
}
Expand Down Expand Up @@ -1209,7 +1209,7 @@ private function _reset()
// Only unset class variables that
// are not callable. Otherwise, we'll
// delete class methods!
foreach($this as $name => $var)
foreach($this as $name => &$var)
{
// Skip properties that are needed for every query
if (in_array($name, array(
Expand Down Expand Up @@ -1265,7 +1265,7 @@ private function _compile($type='', $table='')
// Set the where string
if ( ! empty($this->query_map))
{
foreach($this->query_map as $q)
foreach($this->query_map as &$q)
{
$sql .= $q['conjunction'] . $q['string'];
}
Expand All @@ -1280,7 +1280,7 @@ private function _compile($type='', $table='')
// Set the having string
if ( ! empty($this->having_map))
{
foreach($this->having_map as $h)
foreach($this->having_map as &$h)
{
$sql .= $h['conjunction'] . $h['string'];
}
Expand Down Expand Up @@ -1313,7 +1313,7 @@ private function _compile($type='', $table='')
// Set the where string
if ( ! empty($this->query_map))
{
foreach($this->query_map as $q)
foreach($this->query_map as &$q)
{
$sql .= $q['conjunction'] . $q['string'];
}
Expand All @@ -1326,7 +1326,7 @@ private function _compile($type='', $table='')
// Set the where string
if ( ! empty($this->query_map))
{
foreach($this->query_map as $q)
foreach($this->query_map as &$q)
{
$sql .= $q['conjunction'] . $q['string'];
}
Expand Down
Binary file modified tests/db_files/FB_TEST_DB.FDB
Binary file not shown.

0 comments on commit f555b17

Please sign in to comment.