Skip to content

Commit

Permalink
Cache hash code instead of calculating it on the fly
Browse files Browse the repository at this point in the history
  • Loading branch information
jharting committed Apr 14, 2015
1 parent 73ced19 commit 874bb6e
Showing 1 changed file with 10 additions and 4 deletions.
Expand Up @@ -228,13 +228,22 @@ protected static class ResolvableImpl implements Resolvable {
private final Class<?> rawType;
private final Bean<?> declaringBean;
private final boolean delegate;
private final int hashCode;

protected ResolvableImpl(Class<?> rawType, Set<Type> typeClosure, Bean<?> declaringBean, final Set<QualifierInstance> qualifierInstances, boolean delegate) {
this.typeClosure = typeClosure;
this.rawType = rawType;
this.declaringBean = declaringBean;
this.qualifierInstances = qualifierInstances;
this.delegate = delegate;
this.hashCode = calculateHashCode();
}

@SuppressWarnings("checkstyle:magicnumber")
private int calculateHashCode() {
int hashCode = 17;
hashCode = 31 * hashCode + this.getTypes().hashCode();
return 31 * hashCode + this.qualifierInstances.hashCode();
}

@Override
Expand Down Expand Up @@ -264,10 +273,7 @@ public String toString() {

@Override
public int hashCode() {
int result = 17;
result = 31 * result + this.getTypes().hashCode();
result = 31 * result + this.qualifierInstances.hashCode();
return result;
return hashCode;
}

@Override
Expand Down

0 comments on commit 874bb6e

Please sign in to comment.