From f555b179b4d025316bb87cfe44c18f5593507b70 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 14 May 2012 13:33:41 -0400 Subject: [PATCH] Optimize foreach loops: --- classes/db_pdo.php | 2 +- classes/query_builder.php | 24 ++++++++++++------------ tests/db_files/FB_TEST_DB.FDB | Bin 802816 -> 802816 bytes 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/classes/db_pdo.php b/classes/db_pdo.php index 53bfc5a..33f1b12 100644 --- a/classes/db_pdo.php +++ b/classes/db_pdo.php @@ -107,7 +107,7 @@ abstract class DB_PDO extends PDO { } // Bind the parameters - foreach($data as $k => $value) + foreach($data as $k => &$value) { if(is_numeric($k)) { diff --git a/classes/query_builder.php b/classes/query_builder.php index 5e006f6..679c26c 100644 --- a/classes/query_builder.php +++ b/classes/query_builder.php @@ -237,7 +237,7 @@ class Query_Builder { $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) { @@ -512,7 +512,7 @@ class Query_Builder { $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. @@ -585,7 +585,7 @@ class Query_Builder { // 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; @@ -610,7 +610,7 @@ class Query_Builder { $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. @@ -648,7 +648,7 @@ class Query_Builder { $key = $this->quote_ident($key); $params = array_fill(0, count($val), '?'); - foreach($val as $v) + foreach($val as &$v) { $this->values[] = $v; } @@ -772,7 +772,7 @@ class Query_Builder { // 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; @@ -869,7 +869,7 @@ class Query_Builder { $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); } @@ -1209,7 +1209,7 @@ class Query_Builder { // 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( @@ -1265,7 +1265,7 @@ class Query_Builder { // 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']; } @@ -1280,7 +1280,7 @@ class Query_Builder { // 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']; } @@ -1313,7 +1313,7 @@ class Query_Builder { // 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']; } @@ -1326,7 +1326,7 @@ class Query_Builder { // 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']; } diff --git a/tests/db_files/FB_TEST_DB.FDB b/tests/db_files/FB_TEST_DB.FDB index 05ddb626993c2578c6c5dee990d909335d5caca6..80be6d4603194a5564a16ad5382ca3750e7b1376 100644 GIT binary patch delta 384 zcmYLFJxc>Y5S`7(-R%v*5e+DUWlnB~S7X2ZiaE*qoKS@&^MK;%9@c5zeqobBPNhSN6A@KFy- zI)7{9x~Q=CiVp8}G4BkQ2dfnSQ6!d(r6BF|_B-D3RtKkeu8$s{eB(6N`#8@Z9h?Xs I`nXd01?O8&RsaA1 delta 383 zcmYLEze_?<6h2pddhb1mCqk$teA-J1L4`+Av_zv&LguQ2Q?o-u!=vFgMO$~UA^HoV zpjSh+)EMne8d2I{OS@g4N#}6R$9H~whvRuA&ns;*SShyC@Na}(_>YaSVgqcO00^=6 zD?oMmCCg{W0|X)CjeszdEB2M$xJ(?7BBm&$D6A-=$Wjzl6jQ_%iEEM(VpZQt$tL%A zbMhp1I4nqiSU~Hdo)=@~Nv^SJXmJN_qyrU9Lkm+7!5lmagE9_hA`SZ@19{BAkBCD@ zW}qr^P&Bo7!?|z*sV0xZDPPdX15EmR9bAh}x#p?+pvhq5u73K!E#~UvCvF(H{lc<= zqi>wo&jZY|CEb0)Ii2XCV^5aHs{|7s4y3?x^-d4(^mzwo^kN@f2D;wIvR>_)`wx9w Gul)jBR85Bf