Skip to content

Commit

Permalink
Merge pull request #28 from olivergondza/optimize-RoleMap-getRolesHav…
Browse files Browse the repository at this point in the history
…ingPermission

[JENKINS-18377] Cache Role#hashCode to speed up RoleMap#getRolesHavingPermission
  • Loading branch information
oleg-nenashev committed Jun 2, 2017
2 parents 8dbec9e + 161c035 commit 165538f
Showing 1 changed file with 9 additions and 0 deletions.
Expand Up @@ -53,6 +53,8 @@ public final class Role implements Comparable {
*/
private final Set < Permission > permissions = new HashSet < Permission > ();

private transient Integer cachedHashCode = null;

/**
* Constructor for a global role with no pattern (which is then defaulted to
* {@code .*}).
Expand Down Expand Up @@ -143,6 +145,13 @@ public int compareTo(Object o) {

@Override
public int hashCode() {
if (cachedHashCode == null) {
cachedHashCode = _hashCode();
}
return cachedHashCode;
}

private int _hashCode() {
int hash = 7;
hash = 53 * hash + (this.name != null ? this.name.hashCode() : 0);
hash = 53 * hash + (this.pattern != null ? this.pattern.hashCode() : 0);
Expand Down

0 comments on commit 165538f

Please sign in to comment.