Skip to content

Commit a96c157

Browse files
committed
Applying optimizations to use of count() from 'jrbasso'
1 parent 71df8db commit a96c157

File tree

13 files changed

+69
-54
lines changed

13 files changed

+69
-54
lines changed

cake/libs/configure.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ function delete($var = null) {
373373
$_this =& Configure::getInstance();
374374
$name = $_this->__configVarNames($var);
375375

376-
if (count($name) > 1) {
376+
if (isset($name[1])) {
377377
unset($_this->{$name[0]}[$name[1]]);
378378
} else {
379379
unset($_this->{$name[0]});

cake/libs/controller/components/acl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ function allow($aro, $aco, $actions = "*", $value = 1) {
349349
}
350350
list($save['aro_id'], $save['aco_id']) = array($perms['aro'], $perms['aco']);
351351

352-
if ($perms['link'] != null && count($perms['link']) > 0) {
352+
if ($perms['link'] != null && !empty($perms['link'])) {
353353
$save['id'] = $perms['link'][0][$this->Aro->Permission->alias]['id'];
354354
} else {
355355
unset($save['id']);

cake/libs/controller/controller.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ function validate() {
737737
function validateErrors() {
738738
$objects = func_get_args();
739739

740-
if (!count($objects)) {
740+
if (empty($objects)) {
741741
return false;
742742
}
743743

@@ -747,7 +747,7 @@ function validateErrors() {
747747
$errors = array_merge($errors, $this->{$object->alias}->invalidFields());
748748
}
749749

750-
return $this->validationErrors = (count($errors) ? $errors : false);
750+
return $this->validationErrors = (!empty($errors) ? $errors : false);
751751
}
752752
/**
753753
* Instantiates the correct view class, hands it its data, and uses it to render the view output.

cake/libs/debugger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ function exportVar($var, $recursion = 0) {
403403
}
404404
}
405405
$n = null;
406-
if (count($vars) > 0) {
406+
if (!empty($vars)) {
407407
$n = "\n";
408408
}
409409
return $out . implode(",", $vars) . "{$n})";

cake/libs/folder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ function realpath($path) {
744744
continue;
745745
}
746746
if ($part === '..') {
747-
if (count($newparts) > 0) {
747+
if (!empty($newparts)) {
748748
array_pop($newparts);
749749
continue;
750750
} else {

cake/libs/model/connection_manager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function sourceList() {
135135
function getSourceName(&$source) {
136136
$_this =& ConnectionManager::getInstance();
137137
$names = array_keys($_this->_dataSources);
138-
for ($i = 0; $i < count($names); $i++) {
138+
for ($i = 0, $count = count($names); $i < $count; $i++) {
139139
if ($_this->_dataSources[$names[$i]] === $source) {
140140
return $names[$i];
141141
}

cake/libs/model/datasources/dbo_source.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2039,7 +2039,7 @@ function order($keys, $direction = 'ASC') {
20392039
$keys = array_filter($keys);
20402040
}
20412041

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]))) {
20432043
return '';
20442044
}
20452045

cake/libs/model/model.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ function field($name, $conditions = null, $order = null) {
10791079
return $data[$name[0]][$name[1]];
10801080
}
10811081
}
1082-
if (isset($data[0]) && count($data[0]) > 0) {
1082+
if (!empty($data[0])) {
10831083
$name = key($data[0]);
10841084
return $data[0][$name];
10851085
}

cake/libs/multibyte.php

Lines changed: 53 additions & 38 deletions
Large diffs are not rendered by default.

cake/libs/sanitize.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ function stripTags() {
161161
$params = params(func_get_args());
162162
$str = $params[0];
163163

164-
for ($i = 1; $i < count($params); $i++) {
164+
for ($i = 1, $count = count($params); $i < $count; $i++) {
165165
$str = preg_replace('/<' . $params[$i] . '\b[^>]*>/i', '', $str);
166166
$str = preg_replace('/<\/' . $params[$i] . '[^>]*>/i', '', $str);
167167
}

cake/libs/set.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ function __flatten($results, $key = null) {
10771077
if (!is_null($key)) {
10781078
$id = $key;
10791079
}
1080-
if (is_array($r) && count($r)) {
1080+
if (is_array($r) && !empty($r)) {
10811081
$stack = array_merge($stack, Set::__flatten($r, $id));
10821082
} else {
10831083
$stack[] = array('id' => $id, 'value' => $r);

cake/libs/view/helpers/html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ function style($data, $inline = true) {
410410
* @return string
411411
*/
412412
function getCrumbs($separator = '&raquo;', $startText = false) {
413-
if (count($this->_crumbs)) {
413+
if (!empty($this->_crumbs)) {
414414
$out = array();
415415
if ($startText) {
416416
$out[] = $this->link($startText, '/');

cake/libs/xml.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ function &document() {
566566
* @access public
567567
*/
568568
function hasChildren() {
569-
if (is_array($this->children) && count($this->children) > 0) {
569+
if (is_array($this->children) && !empty($this->children)) {
570570
return true;
571571
}
572572
return false;
@@ -593,22 +593,22 @@ function toString($options = array(), $depth = 0) {
593593
}
594594

595595
$d .= '<' . $this->name();
596-
if (count($this->namespaces) > 0) {
596+
if (!empty($this->namespaces) > 0) {
597597
foreach ($this->namespaces as $key => $val) {
598598
$val = str_replace('"', '\"', $val);
599599
$d .= ' xmlns:' . $key . '="' . $val . '"';
600600
}
601601
}
602602

603603
$parent =& $this->parent();
604-
if ($parent->name === '#document' && count($parent->namespaces) > 0) {
604+
if ($parent->name === '#document' && !empty($parent->namespaces)) {
605605
foreach ($parent->namespaces as $key => $val) {
606606
$val = str_replace('"', '\"', $val);
607607
$d .= ' xmlns:' . $key . '="' . $val . '"';
608608
}
609609
}
610610

611-
if (is_array($this->attributes) && count($this->attributes) > 0) {
611+
if (is_array($this->attributes) && !empty($this->attributes)) {
612612
foreach ($this->attributes as $key => $val) {
613613
if (is_bool($val) && $val === false) {
614614
$val = 0;

0 commit comments

Comments
 (0)