diff options
author | 2018-03-21 12:18:21 -0700 | |
---|---|---|
committer | 2018-03-21 12:20:20 -0700 | |
commit | 977c880be3c1dae87a4c97e730cb439b9c385cdc (patch) | |
tree | 5c46d649c38b4af519f23c5df780892e1bf82ff6 /src | |
parent | f3130e115a58a9df22a4c192c7e71e00c80ac0e6 (diff) |
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
PiperOrigin-RevId: 189947421
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/packages/Attribute.java | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Attribute.java b/src/main/java/com/google/devtools/build/lib/packages/Attribute.java index 61878dd4ef..b7f2ca5f42 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/Attribute.java +++ b/src/main/java/com/google/devtools/build/lib/packages/Attribute.java @@ -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; } /** |