Precompute Attribute#hashCode to remove gc churn from the Object[] allocation done by Attribute#hashCode.
Attribute#hashCode is called a lot by the visitation done by e.g. Rule#getTransition.
RELNOTES: None
@@ -1836,6 +1836,8 @@ public final class Attribute implements Comparable<Attribute> {
private final ImmutableList<RuleAspect<?>> aspects;
+ private final int hashCode;
+
/**
* Constructs a rule attribute with the specified name, type and default value.
*
@@ -1895,6 +1897,21 @@ public final class Attribute implements Comparable<Attribute> {
this.allowedValues = allowedValues;
this.requiredProviders = requiredProviders;
this.aspects = aspects;
+ this.hashCode = Objects.hash(
+ name,
+ type,
+ propertyFlags,
+ defaultValue,
+ configTransition,
+ splitTransitionProvider,
+ allowedRuleClassesForLabels,
+ allowedRuleClassesForLabelsWarning,
+ allowedFileTypesForLabels,
+ validityPredicate,
+ condition,
+ allowedValues,
+ requiredProviders,
+ aspects);
}
/**
@@ -2261,7 +2278,8 @@ public final class Attribute implements Comparable<Attribute> {
return false;
}
Attribute attribute = (Attribute) o;
- return Objects.equals(name, attribute.name)
+ return Objects.equals(hashCode, attribute.hashCode)
+ && Objects.equals(name, attribute.name)
&& Objects.equals(type, attribute.type)
&& Objects.equals(propertyFlags, attribute.propertyFlags)
&& Objects.equals(defaultValue, attribute.defaultValue)
@@ -2280,21 +2298,7 @@ public final class Attribute implements Comparable<Attribute> {
@Override
public int hashCode() {
- return Objects.hash(
- name,
- type,
- propertyFlags,
- defaultValue,
- configTransition,
- splitTransitionProvider,
- allowedRuleClassesForLabels,
- allowedRuleClassesForLabelsWarning,
- allowedFileTypesForLabels,
- validityPredicate,
- condition,
- allowedValues,
- requiredProviders,
- aspects);
+ return hashCode;
}
/**
