MDL-39496 Admin: Reduce excessive is_array tests in admin_category
authorAndrew Nicols <andrew@nicols.co.uk>
Fri, 3 May 2013 13:13:17 +0000 (14:13 +0100)
committerAndrew Nicols <andrew@nicols.co.uk>
Fri, 3 May 2013 13:31:28 +0000 (14:31 +0100)
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

index be26db4..a118ec0 100644 (file)
@@ -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 {