Skip to content

Commit

Permalink
Applying optimizations to use of count() from 'jrbasso'
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Nov 21, 2009
1 parent 71df8db commit a96c157
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 54 deletions.
2 changes: 1 addition & 1 deletion cake/libs/configure.php
Expand Up @@ -373,7 +373,7 @@ function delete($var = null) {
$_this =& Configure::getInstance();
$name = $_this->__configVarNames($var);

if (count($name) > 1) {
if (isset($name[1])) {
unset($_this->{$name[0]}[$name[1]]);
} else {
unset($_this->{$name[0]});
Expand Down
2 changes: 1 addition & 1 deletion cake/libs/controller/components/acl.php
Expand Up @@ -349,7 +349,7 @@ function allow($aro, $aco, $actions = "*", $value = 1) {
}
list($save['aro_id'], $save['aco_id']) = array($perms['aro'], $perms['aco']);

if ($perms['link'] != null && count($perms['link']) > 0) {
if ($perms['link'] != null && !empty($perms['link'])) {
$save['id'] = $perms['link'][0][$this->Aro->Permission->alias]['id'];
} else {
unset($save['id']);
Expand Down
4 changes: 2 additions & 2 deletions cake/libs/controller/controller.php
Expand Up @@ -737,7 +737,7 @@ function validate() {
function validateErrors() {
$objects = func_get_args();

if (!count($objects)) {
if (empty($objects)) {
return false;
}

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

return $this->validationErrors = (count($errors) ? $errors : false);
return $this->validationErrors = (!empty($errors) ? $errors : false);
}
/**
* Instantiates the correct view class, hands it its data, and uses it to render the view output.
Expand Down
2 changes: 1 addition & 1 deletion cake/libs/debugger.php
Expand Up @@ -403,7 +403,7 @@ function exportVar($var, $recursion = 0) {
}
}
$n = null;
if (count($vars) > 0) {
if (!empty($vars)) {
$n = "\n";
}
return $out . implode(",", $vars) . "{$n})";
Expand Down
2 changes: 1 addition & 1 deletion cake/libs/folder.php
Expand Up @@ -744,7 +744,7 @@ function realpath($path) {
continue;
}
if ($part === '..') {
if (count($newparts) > 0) {
if (!empty($newparts)) {
array_pop($newparts);
continue;
} else {
Expand Down
2 changes: 1 addition & 1 deletion cake/libs/model/connection_manager.php
Expand Up @@ -135,7 +135,7 @@ function sourceList() {
function getSourceName(&$source) {
$_this =& ConnectionManager::getInstance();
$names = array_keys($_this->_dataSources);
for ($i = 0; $i < count($names); $i++) {
for ($i = 0, $count = count($names); $i < $count; $i++) {
if ($_this->_dataSources[$names[$i]] === $source) {
return $names[$i];
}
Expand Down
2 changes: 1 addition & 1 deletion cake/libs/model/datasources/dbo_source.php
Expand Up @@ -2039,7 +2039,7 @@ function order($keys, $direction = 'ASC') {
$keys = array_filter($keys);
}

if (empty($keys) || (is_array($keys) && count($keys) && isset($keys[0]) && empty($keys[0]))) {
if (empty($keys) || (is_array($keys) && isset($keys[0]) && empty($keys[0]))) {
return '';
}

Expand Down
2 changes: 1 addition & 1 deletion cake/libs/model/model.php
Expand Up @@ -1079,7 +1079,7 @@ function field($name, $conditions = null, $order = null) {
return $data[$name[0]][$name[1]];
}
}
if (isset($data[0]) && count($data[0]) > 0) {
if (!empty($data[0])) {
$name = key($data[0]);
return $data[0][$name];
}
Expand Down
91 changes: 53 additions & 38 deletions cake/libs/multibyte.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cake/libs/sanitize.php
Expand Up @@ -161,7 +161,7 @@ function stripTags() {
$params = params(func_get_args());
$str = $params[0];

for ($i = 1; $i < count($params); $i++) {
for ($i = 1, $count = count($params); $i < $count; $i++) {
$str = preg_replace('/<' . $params[$i] . '\b[^>]*>/i', '', $str);
$str = preg_replace('/<\/' . $params[$i] . '[^>]*>/i', '', $str);
}
Expand Down
2 changes: 1 addition & 1 deletion cake/libs/set.php
Expand Up @@ -1077,7 +1077,7 @@ function __flatten($results, $key = null) {
if (!is_null($key)) {
$id = $key;
}
if (is_array($r) && count($r)) {
if (is_array($r) && !empty($r)) {
$stack = array_merge($stack, Set::__flatten($r, $id));
} else {
$stack[] = array('id' => $id, 'value' => $r);
Expand Down
2 changes: 1 addition & 1 deletion cake/libs/view/helpers/html.php
Expand Up @@ -410,7 +410,7 @@ function style($data, $inline = true) {
* @return string
*/
function getCrumbs($separator = '&raquo;', $startText = false) {
if (count($this->_crumbs)) {
if (!empty($this->_crumbs)) {
$out = array();
if ($startText) {
$out[] = $this->link($startText, '/');
Expand Down
8 changes: 4 additions & 4 deletions cake/libs/xml.php
Expand Up @@ -566,7 +566,7 @@ function &document() {
* @access public
*/
function hasChildren() {
if (is_array($this->children) && count($this->children) > 0) {
if (is_array($this->children) && !empty($this->children)) {
return true;
}
return false;
Expand All @@ -593,22 +593,22 @@ function toString($options = array(), $depth = 0) {
}

$d .= '<' . $this->name();
if (count($this->namespaces) > 0) {
if (!empty($this->namespaces) > 0) {
foreach ($this->namespaces as $key => $val) {
$val = str_replace('"', '\"', $val);
$d .= ' xmlns:' . $key . '="' . $val . '"';
}
}

$parent =& $this->parent();
if ($parent->name === '#document' && count($parent->namespaces) > 0) {
if ($parent->name === '#document' && !empty($parent->namespaces)) {
foreach ($parent->namespaces as $key => $val) {
$val = str_replace('"', '\"', $val);
$d .= ' xmlns:' . $key . '="' . $val . '"';
}
}

if (is_array($this->attributes) && count($this->attributes) > 0) {
if (is_array($this->attributes) && !empty($this->attributes)) {
foreach ($this->attributes as $key => $val) {
if (is_bool($val) && $val === false) {
$val = 0;
Expand Down

0 comments on commit a96c157

Please sign in to comment.