Precompute `hashCode` in `BuildConfigurationValue.Key`.
Since it is always interned, there's no reason to lazily compute the hash code - it will be called by the interner.
@@ -138,9 +138,8 @@ public class BuildConfigurationValue implements SkyValue {
private static final Interner<Key> keyInterner = BlazeInterners.newWeakInterner();
private final FragmentClassSet fragments;
- final BuildOptions.OptionsDiffForReconstruction optionsDiff;
- // If hashCode really is -1, we'll recompute it from scratch each time. Oh well.
- private volatile int hashCode = -1;
+ private final BuildOptions.OptionsDiffForReconstruction optionsDiff;
+ private final int hashCode;
@AutoCodec.Instantiator
@VisibleForSerialization
@@ -152,6 +151,7 @@ public class BuildConfigurationValue implements SkyValue {
private Key(FragmentClassSet fragments, BuildOptions.OptionsDiffForReconstruction optionsDiff) {
this.fragments = Preconditions.checkNotNull(fragments);
this.optionsDiff = Preconditions.checkNotNull(optionsDiff);
+ this.hashCode = Objects.hash(fragments, optionsDiff);
}
@VisibleForTesting
@@ -182,9 +182,6 @@ public class BuildConfigurationValue implements SkyValue {
@Override
public int hashCode() {
- if (hashCode == -1) {
- hashCode = Objects.hash(fragments, optionsDiff);
- }
return hashCode;
}
