minor #19868 [Security] Optimize RoleHierarchy's buildRoleMap method (Enleur)

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

![image](https://cloud.githubusercontent.com/assets/858989/18271257/df6c4ba0-7439-11e6-8406-e13bdcefe9ca.png)

Commits
-------

c3b68b0 [Security] Optimize RoleHierarchy's buildRoleMap method
This commit is contained in:
Fabien Potencier 2016-09-06 17:21:47 -07:00
commit a630f14659

View File

@ -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]);
}
}
}