Skip to content
This repository
Browse code

Applying optimizations to use of count() from 'jrbasso'

  • Loading branch information...
commit a96c157d948e2f3c1fa55b5d422121c323859626 1 parent 71df8db
Mark Story authored November 21, 2009
2  cake/libs/configure.php
@@ -373,7 +373,7 @@ function delete($var = null) {
373 373
 		$_this =& Configure::getInstance();
374 374
 		$name = $_this->__configVarNames($var);
375 375
 
376  
-		if (count($name) > 1) {
  376
+		if (isset($name[1])) {
377 377
 			unset($_this->{$name[0]}[$name[1]]);
378 378
 		} else {
379 379
 			unset($_this->{$name[0]});
2  cake/libs/controller/components/acl.php
@@ -349,7 +349,7 @@ function allow($aro, $aco, $actions = "*", $value = 1) {
349 349
 		}
350 350
 		list($save['aro_id'], $save['aco_id']) = array($perms['aro'], $perms['aco']);
351 351
 
352  
-		if ($perms['link'] != null && count($perms['link']) > 0) {
  352
+		if ($perms['link'] != null && !empty($perms['link'])) {
353 353
 			$save['id'] = $perms['link'][0][$this->Aro->Permission->alias]['id'];
354 354
 		} else {
355 355
 			unset($save['id']);
4  cake/libs/controller/controller.php
@@ -737,7 +737,7 @@ function validate() {
737 737
 	function validateErrors() {
738 738
 		$objects = func_get_args();
739 739
 
740  
-		if (!count($objects)) {
  740
+		if (empty($objects)) {
741 741
 			return false;
742 742
 		}
743 743
 
@@ -747,7 +747,7 @@ function validateErrors() {
747 747
 			$errors = array_merge($errors, $this->{$object->alias}->invalidFields());
748 748
 		}
749 749
 
750  
-		return $this->validationErrors = (count($errors) ? $errors : false);
  750
+		return $this->validationErrors = (!empty($errors) ? $errors : false);
751 751
 	}
752 752
 /**
753 753
  * Instantiates the correct view class, hands it its data, and uses it to render the view output.
2  cake/libs/debugger.php
@@ -403,7 +403,7 @@ function exportVar($var, $recursion = 0) {
403 403
 					}
404 404
 				}
405 405
 				$n = null;
406  
-				if (count($vars) > 0) {
  406
+				if (!empty($vars)) {
407 407
 					$n = "\n";
408 408
 				}
409 409
 				return $out . implode(",", $vars) . "{$n})";
2  cake/libs/folder.php
@@ -744,7 +744,7 @@ function realpath($path) {
744 744
 				continue;
745 745
 			}
746 746
 			if ($part === '..') {
747  
-				if (count($newparts) > 0) {
  747
+				if (!empty($newparts)) {
748 748
 					array_pop($newparts);
749 749
 					continue;
750 750
 				} else {
2  cake/libs/model/connection_manager.php
@@ -135,7 +135,7 @@ function sourceList() {
135 135
 	function getSourceName(&$source) {
136 136
 		$_this =& ConnectionManager::getInstance();
137 137
 		$names = array_keys($_this->_dataSources);
138  
-		for ($i = 0; $i < count($names); $i++) {
  138
+		for ($i = 0, $count = count($names); $i < $count; $i++) {
139 139
 			if ($_this->_dataSources[$names[$i]] === $source) {
140 140
 				return $names[$i];
141 141
 			}
2  cake/libs/model/datasources/dbo_source.php
@@ -2039,7 +2039,7 @@ function order($keys, $direction = 'ASC') {
2039 2039
 			$keys = array_filter($keys);
2040 2040
 		}
2041 2041
 
2042  
-		if (empty($keys) || (is_array($keys) && count($keys) && isset($keys[0]) && empty($keys[0]))) {
  2042
+		if (empty($keys) || (is_array($keys) && isset($keys[0]) && empty($keys[0]))) {
2043 2043
 			return '';
2044 2044
 		}
2045 2045
 
2  cake/libs/model/model.php
@@ -1079,7 +1079,7 @@ function field($name, $conditions = null, $order = null) {
1079 1079
 					return $data[$name[0]][$name[1]];
1080 1080
 				}
1081 1081
 			}
1082  
-			if (isset($data[0]) && count($data[0]) > 0) {
  1082
+			if (!empty($data[0])) {
1083 1083
 				$name = key($data[0]);
1084 1084
 				return $data[0][$name];
1085 1085
 			}
91  cake/libs/multibyte.php
@@ -36,7 +36,8 @@
36 36
  * @param string $needle The string to find in $haystack.
37 37
  * @param integer $offset The position in $haystack to start searching.
38 38
  * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
39  
- * @return integer|boolean The numeric position of the first occurrence of $needle in the $haystack string, or false if $needle is not found.
  39
+ * @return integer|boolean The numeric position of the first occurrence of $needle in the $haystack string, or false 
  40
+ *    if $needle is not found.
40 41
  */
41 42
 if (!function_exists('mb_stripos')) {
42 43
 	function mb_stripos($haystack, $needle, $offset = 0, $encoding = null) {
@@ -49,8 +50,9 @@ function mb_stripos($haystack, $needle, $offset = 0, $encoding = null) {
49 50
  * @param string $haystack The string from which to get the first occurrence of $needle.
50 51
  * @param string $needle The string to find in $haystack.
51 52
  * @param boolean $part Determines which portion of $haystack this function returns.
52  
- *                If set to true, it returns all of $haystack from the beginning to the first occurrence of $needle.
53  
- *                If set to false, it returns all of $haystack from the first occurrence of $needle to the end, Default value is false.
  53
+ *    If set to true, it returns all of $haystack from the beginning to the first occurrence of $needle.
  54
+ *    If set to false, it returns all of $haystack from the first occurrence of $needle to the end, 
  55
+ *    Default value is false.
54 56
  * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
55 57
  * @return string|boolean The portion of $haystack, or false if $needle is not found.
56 58
  */
@@ -65,7 +67,7 @@ function mb_stristr($haystack, $needle, $part = false, $encoding = null) {
65 67
  * @param string $string The string being checked for length.
66 68
  * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
67 69
  * @return integer The number of characters in string $string having character encoding encoding.
68  
- *                 A multi-byte character is counted as 1.
  70
+ *    A multi-byte character is counted as 1.
69 71
  */
70 72
 if (!function_exists('mb_strlen')) {
71 73
 	function mb_strlen($string, $encoding = null) {
@@ -80,7 +82,7 @@ function mb_strlen($string, $encoding = null) {
80 82
  * @param integer $offset The search offset. If it is not specified, 0 is used.
81 83
  * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
82 84
  * @return integer|boolean The numeric position of the first occurrence of $needle in the $haystack string.
83  
- *                         If $needle is not found, it returns false.
  85
+ *    If $needle is not found, it returns false.
84 86
  */
85 87
 if (!function_exists('mb_strpos')) {
86 88
 	function mb_strpos($haystack, $needle, $offset = 0, $encoding = null) {
@@ -93,8 +95,9 @@ function mb_strpos($haystack, $needle, $offset = 0, $encoding = null) {
93 95
  * @param string $haystack The string from which to get the last occurrence of $needle.
94 96
  * @param string $needle The string to find in $haystack.
95 97
  * @param boolean $part Determines which portion of $haystack this function returns.
96  
- *                      If set to true, it returns all of $haystack from the beginning to the last occurrence of $needle.
97  
- *                      If set to false, it returns all of $haystack from the last occurrence of $needle to the end, Default value is false.
  98
+ *    If set to true, it returns all of $haystack from the beginning to the last occurrence of $needle.
  99
+ *    If set to false, it returns all of $haystack from the last occurrence of $needle to the end, 
  100
+ *    Default value is false.
98 101
  * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
99 102
  * @return string|boolean The portion of $haystack. or false if $needle is not found.
100 103
  */
@@ -109,8 +112,9 @@ function mb_strrchr($haystack, $needle, $part = false, $encoding = null) {
109 112
  * @param string $haystack The string from which to get the last occurrence of $needle.
110 113
  * @param string $needle The string to find in $haystack.
111 114
  * @param boolean $part Determines which portion of $haystack this function returns.
112  
- *                      If set to true, it returns all of $haystack from the beginning to the last occurrence of $needle.
113  
- *                      If set to false, it returns all of $haystack from the last occurrence of $needle to the end, Default value is false.
  115
+ *    If set to true, it returns all of $haystack from the beginning to the last occurrence of $needle.
  116
+ *    If set to false, it returns all of $haystack from the last occurrence of $needle to the end, 
  117
+ *    Default value is false.
114 118
  * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
115 119
  * @return string|boolean The portion of $haystack. or false if $needle is not found.
116 120
  */
@@ -126,7 +130,8 @@ function mb_strrichr($haystack, $needle, $part = false, $encoding = null) {
126 130
  * @param string $needle The string to find in $haystack.
127 131
  * @param integer $offset The position in $haystack to start searching.
128 132
  * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
129  
- * @return integer|boolean The numeric position of the last occurrence of $needle in the $haystack string, or false if $needle is not found.
  133
+ * @return integer|boolean The numeric position of the last occurrence of $needle in the $haystack string, 
  134
+ *    or false if $needle is not found.
130 135
  */
131 136
 if (!function_exists('mb_strripos')) {
132 137
 	function mb_strripos($haystack, $needle, $offset = 0, $encoding = null) {
@@ -139,9 +144,10 @@ function mb_strripos($haystack, $needle, $offset = 0, $encoding = null) {
139 144
  * @param string $haystack The string being checked, for the last occurrence of $needle.
140 145
  * @param string $needle The string to find in $haystack.
141 146
  * @param integer $offset May be specified to begin searching an arbitrary number of characters into the string.
142  
- *                        Negative values will stop searching at an arbitrary point prior to the end of the string.
  147
+ *    Negative values will stop searching at an arbitrary point prior to the end of the string.
143 148
  * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
144  
- * @return integer|boolean The numeric position of the last occurrence of $needle in the $haystack string. If $needle is not found, it returns false.
  149
+ * @return integer|boolean The numeric position of the last occurrence of $needle in the $haystack string. 
  150
+ *    If $needle is not found, it returns false.
145 151
  */
146 152
 if (!function_exists('mb_strrpos')) {
147 153
 	function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null) {
@@ -154,8 +160,9 @@ function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null) {
154 160
  * @param string $haystack The string from which to get the first occurrence of $needle.
155 161
  * @param string $needle The string to find in $haystack
156 162
  * @param boolean $part Determines which portion of $haystack this function returns.
157  
- *                      If set to true, it returns all of $haystack from the beginning to the first occurrence of $needle.
158  
- *                      If set to false, it returns all of $haystack from the first occurrence of $needle to the end, Default value is FALSE.
  163
+ *    If set to true, it returns all of $haystack from the beginning to the first occurrence of $needle.
  164
+ *    If set to false, it returns all of $haystack from the first occurrence of $needle to the end, 
  165
+ *    Default value is FALSE.
159 166
  * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
160 167
  * @return string|boolean The portion of $haystack, or true if $needle is not found.
161 168
  */
@@ -220,12 +227,13 @@ function mb_substr($string, $start, $length = null, $encoding = null) {
220 227
  *
221 228
  * @param string $str The string being encoded
222 229
  * @param string $charset specifies the name of the character set in which str is represented in.
223  
- * 						The default value is determined by the current NLS setting (mbstring.language).
224  
- * @param string $transfer_encoding specifies the scheme of MIME encoding. It should be either "B" (Base64) or "Q" (Quoted-Printable).
225  
- * 						Falls back to "B" if not given.
226  
- * @param string $linefeed specifies the EOL (end-of-line) marker with which mb_encode_mimeheader() performs line-folding
227  
- * 						(a » RFC term, the act of breaking a line longer than a certain length into multiple lines.
228  
- * 						The length is currently hard-coded to 74 characters). Falls back to "\r\n" (CRLF) if not given.
  230
+ *    The default value is determined by the current NLS setting (mbstring.language).
  231
+ * @param string $transfer_encoding specifies the scheme of MIME encoding. 
  232
+ *    It should be either "B" (Base64) or "Q" (Quoted-Printable). Falls back to "B" if not given.
  233
+ * @param string $linefeed specifies the EOL (end-of-line) marker with which 
  234
+ *    mb_encode_mimeheader() performs line-folding
  235
+ *    (a » RFC term, the act of breaking a line longer than a certain length into multiple lines.
  236
+ *    The length is currently hard-coded to 74 characters). Falls back to "\r\n" (CRLF) if not given.
229 237
  * @param integer $indent [definition unknown and appears to have no affect]
230 238
  * @return string A converted version of the string represented in ASCII.
231 239
  */
@@ -300,7 +308,7 @@ function utf8($string) {
300 308
 			if ($value < 128) {
301 309
 				$map[] = $value;
302 310
 			} else {
303  
-				if (count($values) == 0) {
  311
+				if (empty($values)) {
304 312
 					$find = ($value < 224) ? 2 : 3;
305 313
 				}
306 314
 				$values[] = $value;
@@ -350,7 +358,8 @@ function ascii($array) {
350 358
  * @param multi-byte string $haystack The string from which to get the position of the first occurrence of $needle.
351 359
  * @param multi-byte string $needle The string to find in $haystack.
352 360
  * @param integer $offset The position in $haystack to start searching.
353  
- * @return integer|boolean The numeric position of the first occurrence of $needle in the $haystack string, or false if $needle is not found.
  361
+ * @return integer|boolean The numeric position of the first occurrence of $needle in the $haystack string, 
  362
+ *    or false if $needle is not found.
354 363
  * @access public
355 364
  * @static
356 365
  */
@@ -368,8 +377,9 @@ function stripos($haystack, $needle, $offset = 0) {
368 377
  * @param string $haystack The string from which to get the first occurrence of $needle.
369 378
  * @param string $needle The string to find in $haystack.
370 379
  * @param boolean $part Determines which portion of $haystack this function returns.
371  
- *                If set to true, it returns all of $haystack from the beginning to the first occurrence of $needle.
372  
- *                If set to false, it returns all of $haystack from the first occurrence of $needle to the end, Default value is false.
  380
+ *    If set to true, it returns all of $haystack from the beginning to the first occurrence of $needle.
  381
+ *    If set to false, it returns all of $haystack from the first occurrence of $needle to the end, 
  382
+ *    Default value is false.
373 383
  * @return int|boolean The portion of $haystack, or false if $needle is not found.
374 384
  * @access public
375 385
  * @static
@@ -445,7 +455,7 @@ function strlen($string) {
445 455
  * @param string $needle The position counted from the beginning of haystack.
446 456
  * @param integer $offset The search offset. If it is not specified, 0 is used.
447 457
  * @return integer|boolean The numeric position of the first occurrence of $needle in the $haystack string.
448  
- *                         If $needle is not found, it returns false.
  458
+ *    If $needle is not found, it returns false.
449 459
  * @access public
450 460
  * @static
451 461
  */
@@ -488,8 +498,9 @@ function strpos($haystack, $needle, $offset = 0) {
488 498
  * @param string $haystack The string from which to get the last occurrence of $needle.
489 499
  * @param string $needle The string to find in $haystack.
490 500
  * @param boolean $part Determines which portion of $haystack this function returns.
491  
- *                      If set to true, it returns all of $haystack from the beginning to the last occurrence of $needle.
492  
- *                      If set to false, it returns all of $haystack from the last occurrence of $needle to the end, Default value is false.
  501
+ *    If set to true, it returns all of $haystack from the beginning to the last occurrence of $needle.
  502
+ *    If set to false, it returns all of $haystack from the last occurrence of $needle to the end,
  503
+ *    Default value is false.
493 504
  * @return string|boolean The portion of $haystack. or false if $needle is not found.
494 505
  * @access public
495 506
  * @static
@@ -548,8 +559,9 @@ function strrchr($haystack, $needle, $part = false) {
548 559
  * @param string $haystack The string from which to get the last occurrence of $needle.
549 560
  * @param string $needle The string to find in $haystack.
550 561
  * @param boolean $part Determines which portion of $haystack this function returns.
551  
- *                      If set to true, it returns all of $haystack from the beginning to the last occurrence of $needle.
552  
- *                      If set to false, it returns all of $haystack from the last occurrence of $needle to the end, Default value is false.
  562
+ *    If set to true, it returns all of $haystack from the beginning to the last occurrence of $needle.
  563
+ *    If set to false, it returns all of $haystack from the last occurrence of $needle to the end, 
  564
+ *    Default value is false.
553 565
  * @return string|boolean The portion of $haystack. or false if $needle is not found.
554 566
  * @access public
555 567
  * @static
@@ -610,7 +622,8 @@ function strrichr($haystack, $needle, $part = false) {
610 622
  * @param string $haystack The string from which to get the position of the last occurrence of $needle.
611 623
  * @param string $needle The string to find in $haystack.
612 624
  * @param integer $offset The position in $haystack to start searching.
613  
- * @return integer|boolean The numeric position of the last occurrence of $needle in the $haystack string, or false if $needle is not found.
  625
+ * @return integer|boolean The numeric position of the last occurrence of $needle in the $haystack string, 
  626
+ *    or false if $needle is not found.
614 627
  * @access public
615 628
  * @static
616 629
  */
@@ -661,8 +674,9 @@ function strripos($haystack, $needle, $offset = 0) {
661 674
  * @param string $haystack The string being checked, for the last occurrence of $needle.
662 675
  * @param string $needle The string to find in $haystack.
663 676
  * @param integer $offset May be specified to begin searching an arbitrary number of characters into the string.
664  
- *                        Negative values will stop searching at an arbitrary point prior to the end of the string.
665  
- * @return integer|boolean The numeric position of the last occurrence of $needle in the $haystack string. If $needle is not found, it returns false.
  677
+ *    Negative values will stop searching at an arbitrary point prior to the end of the string.
  678
+ * @return integer|boolean The numeric position of the last occurrence of $needle in the $haystack string. 
  679
+ *    If $needle is not found, it returns false.
666 680
  * @access public
667 681
  * @static
668 682
  */
@@ -711,8 +725,9 @@ function strrpos($haystack, $needle, $offset = 0) {
711 725
  * @param string $haystack The string from which to get the first occurrence of $needle.
712 726
  * @param string $needle The string to find in $haystack
713 727
  * @param boolean $part Determines which portion of $haystack this function returns.
714  
- *                      If set to true, it returns all of $haystack from the beginning to the first occurrence of $needle.
715  
- *                      If set to false, it returns all of $haystack from the first occurrence of $needle to the end, Default value is FALSE.
  728
+ *    If set to true, it returns all of $haystack from the beginning to the first occurrence of $needle.
  729
+ *    If set to false, it returns all of $haystack from the first occurrence of $needle to the end, 
  730
+ *    Default value is FALSE.
716 731
  * @return string|boolean The portion of $haystack, or true if $needle is not found.
717 732
  * @access public
718 733
  * @static
@@ -853,14 +868,14 @@ function strtoupper($string) {
853 868
 						if ($length > 1 && count($keys[$key]['lower']) > 1) {
854 869
 							$j = 0;
855 870
 
856  
-							for ($ii = 0; $ii < count($keys[$key]['lower']); $ii++) {
  871
+							for ($ii = 0, $count = count($keys[$key]['lower']); $ii < $count; $ii++) {
857 872
 								$nextChar = $utf8Map[$i + $ii];
858 873
 
859 874
 								if (isset($nextChar) && ($nextChar == $keys[$key]['lower'][$j + $ii])) {
860 875
 									$replace++;
861 876
 								}
862 877
 							}
863  
-							if ($replace == count($keys[$key]['lower'])) {
  878
+							if ($replace == $count) {
864 879
 								$upperCase[] = $keys[$key]['upper'];
865 880
 								$replaced = array_merge($replaced, array_values($keys[$key]['lower']));
866 881
 								$matched = true;
@@ -873,14 +888,14 @@ function strtoupper($string) {
873 888
 
874 889
 								if (in_array($nextChar, $keys[$ii]['lower'])) {
875 890
 
876  
-									for ($jj = 0; $jj < count($keys[$ii]['lower']); $jj++) {
  891
+									for ($jj = 0, $count = count($keys[$ii]['lower']); $jj < $count; $jj++) {
877 892
 										$nextChar = $utf8Map[$i + $jj];
878 893
 
879 894
 										if (isset($nextChar) && ($nextChar == $keys[$ii]['lower'][$j + $jj])) {
880 895
 											$replace++;
881 896
 										}
882 897
 									}
883  
-									if ($replace == count($keys[$ii]['lower'])) {
  898
+									if ($replace == $count) {
884 899
 										$upperCase[] = $keys[$ii]['upper'];
885 900
 										$replaced = array_merge($replaced, array_values($keys[$ii]['lower']));
886 901
 										$matched = true;
2  cake/libs/sanitize.php
@@ -161,7 +161,7 @@ function stripTags() {
161 161
 		$params = params(func_get_args());
162 162
 		$str = $params[0];
163 163
 
164  
-		for ($i = 1; $i < count($params); $i++) {
  164
+		for ($i = 1, $count = count($params); $i < $count; $i++) {
165 165
 			$str = preg_replace('/<' . $params[$i] . '\b[^>]*>/i', '', $str);
166 166
 			$str = preg_replace('/<\/' . $params[$i] . '[^>]*>/i', '', $str);
167 167
 		}
2  cake/libs/set.php
@@ -1077,7 +1077,7 @@ function __flatten($results, $key = null) {
1077 1077
 			if (!is_null($key)) {
1078 1078
 				$id = $key;
1079 1079
 			}
1080  
-			if (is_array($r) && count($r)) {
  1080
+			if (is_array($r) && !empty($r)) {
1081 1081
 				$stack = array_merge($stack, Set::__flatten($r, $id));
1082 1082
 			} else {
1083 1083
 				$stack[] = array('id' => $id, 'value' => $r);
2  cake/libs/view/helpers/html.php
@@ -410,7 +410,7 @@ function style($data, $inline = true) {
410 410
  * @return string
411 411
  */
412 412
 	function getCrumbs($separator = '&raquo;', $startText = false) {
413  
-		if (count($this->_crumbs)) {
  413
+		if (!empty($this->_crumbs)) {
414 414
 			$out = array();
415 415
 			if ($startText) {
416 416
 				$out[] = $this->link($startText, '/');
8  cake/libs/xml.php
@@ -566,7 +566,7 @@ function &document() {
566 566
  * @access public
567 567
  */
568 568
 	function hasChildren() {
569  
-		if (is_array($this->children) && count($this->children) > 0) {
  569
+		if (is_array($this->children) && !empty($this->children)) {
570 570
 			return true;
571 571
 		}
572 572
 		return false;
@@ -593,7 +593,7 @@ function toString($options = array(), $depth = 0) {
593 593
 			}
594 594
 
595 595
 			$d .= '<' . $this->name();
596  
-			if (count($this->namespaces) > 0) {
  596
+			if (!empty($this->namespaces) > 0) {
597 597
 				foreach ($this->namespaces as $key => $val) {
598 598
 					$val = str_replace('"', '\"', $val);
599 599
 					$d .= ' xmlns:' . $key . '="' . $val . '"';
@@ -601,14 +601,14 @@ function toString($options = array(), $depth = 0) {
601 601
 			}
602 602
 
603 603
 			$parent =& $this->parent();
604  
-			if ($parent->name === '#document' && count($parent->namespaces) > 0) {
  604
+			if ($parent->name === '#document' && !empty($parent->namespaces)) {
605 605
 				foreach ($parent->namespaces as $key => $val) {
606 606
 					$val = str_replace('"', '\"', $val);
607 607
 					$d .= ' xmlns:' . $key . '="' . $val . '"';
608 608
 				}
609 609
 			}
610 610
 
611  
-			if (is_array($this->attributes) && count($this->attributes) > 0) {
  611
+			if (is_array($this->attributes) && !empty($this->attributes)) {
612 612
 				foreach ($this->attributes as $key => $val) {
613 613
 					if (is_bool($val) && $val === false) {
614 614
 						$val = 0;

0 notes on commit a96c157

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