From 42b53d4650064023783f52f4588ade0fb1f2c4eb Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 3 May 2013 14:13:17 +0100 Subject: [PATCH] MDL-39496 Admin: Reduce excessive is_array tests in admin_category admin_category::category_cache is a protected value which is only ever treated as an array. We shouldn't need to test that it's an array each time we use it. --- lib/adminlib.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/adminlib.php b/lib/adminlib.php index be26db438df..a118ec023c2 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -871,7 +871,7 @@ class admin_category implements parentable_part_of_admin_tree { * defaults to false */ public function locate($name, $findpath=false) { - if (is_array($this->category_cache) and !isset($this->category_cache[$this->name])) { + if (!isset($this->category_cache[$this->name])) { // somebody much have purged the cache $this->category_cache[$this->name] = $this; } @@ -885,7 +885,7 @@ class admin_category implements parentable_part_of_admin_tree { } // quick category lookup - if (!$findpath and is_array($this->category_cache) and isset($this->category_cache[$name])) { + if (!$findpath and isset($this->category_cache[$name])) { return $this->category_cache[$name]; } @@ -938,11 +938,9 @@ class admin_category implements parentable_part_of_admin_tree { foreach($this->children as $precedence => $child) { if ($child->name == $name) { // clear cache and delete self - if (is_array($this->category_cache)) { - while($this->category_cache) { - // delete the cache, but keep the original array address - array_pop($this->category_cache); - } + while($this->category_cache) { + // delete the cache, but keep the original array address + array_pop($this->category_cache); } unset($this->children[$precedence]); return true; @@ -1010,7 +1008,7 @@ class admin_category implements parentable_part_of_admin_tree { ); } } - if (is_array($this->category_cache) and ($something instanceof admin_category)) { + if ($something instanceof admin_category) { if (isset($this->category_cache[$something->name])) { debugging('Duplicate admin category name: '.$something->name); } else {