diff options
author | Fabien Potencier <fabien.potencier@gmail.com> | 2016-09-06 17:21:47 -0700 |
---|---|---|
committer | Fabien Potencier <fabien.potencier@gmail.com> | 2016-09-06 17:21:47 -0700 |
commit | bd170760b502967a6b42f90fd8db57646683a345 (patch) | |
tree | d20f419a901d81c60175aa358c9b09b7a51c1d8c | |
parent | b271c97b4345e8d2a488868b2acec152caa451c1 (diff) | |
parent | 2174a8c2e3fb6190a24d823e5b4a08f2aab631ce (diff) | |
download | symfony-security-bd170760b502967a6b42f90fd8db57646683a345.zip symfony-security-bd170760b502967a6b42f90fd8db57646683a345.tar.gz symfony-security-bd170760b502967a6b42f90fd8db57646683a345.tar.bz2 |
minor #19868 [Security] Optimize RoleHierarchy's buildRoleMap method (Enleur)v2.7.18
This PR was squashed before being merged into the 2.7 branch (closes #19868).
Discussion
----------
[Security] Optimize RoleHierarchy's buildRoleMap method
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | no
| License | MIT
| Doc PR | no
I have an issue with a large role hierarchy(~150 roles). Optimized it a little bit

Commits
-------
c3b68b0 [Security] Optimize RoleHierarchy's buildRoleMap method
-rw-r--r-- | Core/Role/RoleHierarchy.php | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/Core/Role/RoleHierarchy.php b/Core/Role/RoleHierarchy.php index 793007e..95e76ee 100644 --- a/Core/Role/RoleHierarchy.php +++ b/Core/Role/RoleHierarchy.php @@ -65,9 +65,17 @@ class RoleHierarchy implements RoleHierarchyInterface } $visited[] = $role; - $this->map[$main] = array_unique(array_merge($this->map[$main], $this->hierarchy[$role])); - $additionalRoles = array_merge($additionalRoles, array_diff($this->hierarchy[$role], $visited)); + + foreach ($this->hierarchy[$role] as $roleToAdd) { + $this->map[$main][] = $roleToAdd; + } + + foreach (array_diff($this->hierarchy[$role], $visited) as $additionalRole) { + $additionalRoles[] = $additionalRole; + } } + + $this->map[$main] = array_unique($this->map[$main]); } } } |