浏览代码

Use isset in permission exists for improved efficiency(#7126)

Using isset on the key name of the array allows it to use a hash table lookup to improve the lookup times for a permission. The permission name is not set if it does not exist for the current user.
frytimo 1 年之前
父节点
当前提交
df242c63e2
共有 1 个文件被更改,包括 3 次插入12 次删除
  1. 3 12
      resources/classes/permissions.php

+ 3 - 12
resources/classes/permissions.php

@@ -127,21 +127,12 @@ if (!class_exists('permissions')) {
 				return true;
 				return true;
 			}
 			}
 
 
-			//set default to false
-			$result = false;
-
 			//search for the permission
 			//search for the permission
-			if (!empty($this->permissions) && !empty($permission_name)) {
-				foreach($this->permissions as $key => $value) {
-					if ($key == $permission_name) {
-						$result = true;
-						break;
-					}
-				}
+			if (!empty($permission_name)) {
+				return isset($this->permissions[$permission_name]);
 			}
 			}
 
 
-			//return the result
-			return $result;
+			return false;
 		}
 		}
 
 
 		/**
 		/**