Skip to content
This repository
Browse code

Optimization for Hash method

  • Loading branch information...
commit ecdf0e6c6cddd3108dae7abbe71bcba7d98a620a 1 parent 3e28326
Juan Basso authored June 24, 2012

Showing 1 changed file with 4 additions and 10 deletions. Show diff stats Hide diff stats

  1. 14  lib/Cake/Utility/Hash.php
14  lib/Cake/Utility/Hash.php
@@ -47,7 +47,7 @@ public static function get(array $data, $path) {
47 47
 		} else {
48 48
 			$parts = $path;
49 49
 		}
50  
-		while (($key = array_shift($parts)) !== null) {
  50
+		foreach ($parts as $key) {
51 51
 			if (is_array($data) && isset($data[$key])) {
52 52
 				$data =& $data[$key];
53 53
 			} else {
@@ -106,8 +106,7 @@ public static function extract(array $data, $path) {
106 106
 
107 107
 		$context = array($_key => array($data));
108 108
 
109  
-		do {
110  
-			$token = array_shift($tokens);
  109
+		foreach ($tokens as $token) {
111 110
 			$next = array();
112 111
 
113 112
 			$conditions = false;
@@ -137,7 +136,7 @@ public static function extract(array $data, $path) {
137 136
 			}
138 137
 			$context = array($_key => $next);
139 138
 
140  
-		} while (!empty($tokens));
  139
+		}
141 140
 		return $context[$_key];
142 141
 	}
143 142
 
@@ -176,12 +175,7 @@ protected static function _matches(array $data, $selector) {
176 175
 			PREG_SET_ORDER
177 176
 		);
178 177
 
179  
-		$ok = true;
180  
-		while ($ok) {
181  
-			if (empty($conditions)) {
182  
-				break;
183  
-			}
184  
-			$cond = array_shift($conditions);
  178
+		foreach ($conditions as $cond) {
185 179
 			$attr = $cond['attr'];
186 180
 			$op = isset($cond['op']) ? $cond['op'] : null;
187 181
 			$val = isset($cond['val']) ? $cond['val'] : null;

1 note on commit ecdf0e6

Zach Bloomquist

Simply beautiful. :)

Please sign in to comment.
Something went wrong with that request. Please try again.