Optimize foreach loops:
This commit is contained in:
parent
bf3b072124
commit
f555b179b4
@ -107,7 +107,7 @@ abstract class DB_PDO extends PDO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Bind the parameters
|
// Bind the parameters
|
||||||
foreach($data as $k => $value)
|
foreach($data as $k => &$value)
|
||||||
{
|
{
|
||||||
if(is_numeric($k))
|
if(is_numeric($k))
|
||||||
{
|
{
|
||||||
|
@ -237,7 +237,7 @@ class Query_Builder {
|
|||||||
$fields_array = array_map('trim', $fields_array);
|
$fields_array = array_map('trim', $fields_array);
|
||||||
|
|
||||||
// Split on 'As'
|
// Split on 'As'
|
||||||
foreach ($fields_array as $key => $field)
|
foreach ($fields_array as $key => &$field)
|
||||||
{
|
{
|
||||||
if (stripos($field, 'as') !== FALSE)
|
if (stripos($field, 'as') !== FALSE)
|
||||||
{
|
{
|
||||||
@ -512,7 +512,7 @@ class Query_Builder {
|
|||||||
$where = $this->_where($key, $val);
|
$where = $this->_where($key, $val);
|
||||||
|
|
||||||
// Create key/value placeholders
|
// Create key/value placeholders
|
||||||
foreach($where as $f => $val)
|
foreach($where as $f => &$val)
|
||||||
{
|
{
|
||||||
// Split each key by spaces, in case there
|
// Split each key by spaces, in case there
|
||||||
// is an operator such as >, <, !=, etc.
|
// is an operator such as >, <, !=, etc.
|
||||||
@ -585,7 +585,7 @@ class Query_Builder {
|
|||||||
// Array or object, loop through and add to the where array
|
// Array or object, loop through and add to the where array
|
||||||
elseif ( ! is_scalar($key))
|
elseif ( ! is_scalar($key))
|
||||||
{
|
{
|
||||||
foreach($key as $k => $v)
|
foreach($key as $k => &$v)
|
||||||
{
|
{
|
||||||
$where[$k] = $v;
|
$where[$k] = $v;
|
||||||
$this->values[] = $v;
|
$this->values[] = $v;
|
||||||
@ -610,7 +610,7 @@ class Query_Builder {
|
|||||||
$where = $this->_where($key, $val);
|
$where = $this->_where($key, $val);
|
||||||
|
|
||||||
// Create key/value placeholders
|
// Create key/value placeholders
|
||||||
foreach($where as $f => $val)
|
foreach($where as $f => &$val)
|
||||||
{
|
{
|
||||||
// Split each key by spaces, in case there
|
// Split each key by spaces, in case there
|
||||||
// is an operator such as >, <, !=, etc.
|
// is an operator such as >, <, !=, etc.
|
||||||
@ -648,7 +648,7 @@ class Query_Builder {
|
|||||||
$key = $this->quote_ident($key);
|
$key = $this->quote_ident($key);
|
||||||
$params = array_fill(0, count($val), '?');
|
$params = array_fill(0, count($val), '?');
|
||||||
|
|
||||||
foreach($val as $v)
|
foreach($val as &$v)
|
||||||
{
|
{
|
||||||
$this->values[] = $v;
|
$this->values[] = $v;
|
||||||
}
|
}
|
||||||
@ -772,7 +772,7 @@ class Query_Builder {
|
|||||||
// Object or array
|
// Object or array
|
||||||
elseif ( ! is_scalar($key))
|
elseif ( ! is_scalar($key))
|
||||||
{
|
{
|
||||||
foreach($key as $k => $v)
|
foreach($key as $k => &$v)
|
||||||
{
|
{
|
||||||
$this->set_array_keys[] = $k;
|
$this->set_array_keys[] = $k;
|
||||||
$this->values[] = $v;
|
$this->values[] = $v;
|
||||||
@ -869,7 +869,7 @@ class Query_Builder {
|
|||||||
$order_clauses = array();
|
$order_clauses = array();
|
||||||
|
|
||||||
// Flatten key/val pairs into an array of space-separated pairs
|
// 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);
|
$order_clauses[] = $k . ' ' . strtoupper($v);
|
||||||
}
|
}
|
||||||
@ -1209,7 +1209,7 @@ class Query_Builder {
|
|||||||
// Only unset class variables that
|
// Only unset class variables that
|
||||||
// are not callable. Otherwise, we'll
|
// are not callable. Otherwise, we'll
|
||||||
// delete class methods!
|
// delete class methods!
|
||||||
foreach($this as $name => $var)
|
foreach($this as $name => &$var)
|
||||||
{
|
{
|
||||||
// Skip properties that are needed for every query
|
// Skip properties that are needed for every query
|
||||||
if (in_array($name, array(
|
if (in_array($name, array(
|
||||||
@ -1265,7 +1265,7 @@ class Query_Builder {
|
|||||||
// Set the where string
|
// Set the where string
|
||||||
if ( ! empty($this->query_map))
|
if ( ! empty($this->query_map))
|
||||||
{
|
{
|
||||||
foreach($this->query_map as $q)
|
foreach($this->query_map as &$q)
|
||||||
{
|
{
|
||||||
$sql .= $q['conjunction'] . $q['string'];
|
$sql .= $q['conjunction'] . $q['string'];
|
||||||
}
|
}
|
||||||
@ -1280,7 +1280,7 @@ class Query_Builder {
|
|||||||
// Set the having string
|
// Set the having string
|
||||||
if ( ! empty($this->having_map))
|
if ( ! empty($this->having_map))
|
||||||
{
|
{
|
||||||
foreach($this->having_map as $h)
|
foreach($this->having_map as &$h)
|
||||||
{
|
{
|
||||||
$sql .= $h['conjunction'] . $h['string'];
|
$sql .= $h['conjunction'] . $h['string'];
|
||||||
}
|
}
|
||||||
@ -1313,7 +1313,7 @@ class Query_Builder {
|
|||||||
// Set the where string
|
// Set the where string
|
||||||
if ( ! empty($this->query_map))
|
if ( ! empty($this->query_map))
|
||||||
{
|
{
|
||||||
foreach($this->query_map as $q)
|
foreach($this->query_map as &$q)
|
||||||
{
|
{
|
||||||
$sql .= $q['conjunction'] . $q['string'];
|
$sql .= $q['conjunction'] . $q['string'];
|
||||||
}
|
}
|
||||||
@ -1326,7 +1326,7 @@ class Query_Builder {
|
|||||||
// Set the where string
|
// Set the where string
|
||||||
if ( ! empty($this->query_map))
|
if ( ! empty($this->query_map))
|
||||||
{
|
{
|
||||||
foreach($this->query_map as $q)
|
foreach($this->query_map as &$q)
|
||||||
{
|
{
|
||||||
$sql .= $q['conjunction'] . $q['string'];
|
$sql .= $q['conjunction'] . $q['string'];
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user