Permalink
Browse files

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.
  • Loading branch information...
1 parent 95190fd commit 42b53d4650064023783f52f4588ade0fb1f2c4eb @andrewnicols andrewnicols committed May 3, 2013
Showing with 6 additions and 8 deletions.
  1. +6 −8 lib/adminlib.php
View
@@ -871,7 +871,7 @@ public function __construct($name, $visiblename, $hidden=false) {
* 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 @@ public function locate($name, $findpath=false) {
}
// 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 @@ public function prune($name) {
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 @@ public function add($parentname, $something, $beforesibling = null) {
);
}
}
- 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 {

0 comments on commit 42b53d4

Please sign in to comment.