Skip to content

Commit

Permalink
Precompute hashCode in BuildConfigurationValue.Key.
Browse files Browse the repository at this point in the history
Since it is always interned, there's no reason to lazily compute the hash code - it will be called by the interner.

PiperOrigin-RevId: 368515456
  • Loading branch information
justinhorvitz authored and Copybara-Service committed Apr 14, 2021
1 parent 020dd5f commit e37a9ab
Showing 1 changed file with 3 additions and 6 deletions.
Expand Up @@ -138,9 +138,8 @@ public static final class Key implements SkyKey, Serializable {
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
Expand All @@ -152,6 +151,7 @@ static Key create(
private Key(FragmentClassSet fragments, BuildOptions.OptionsDiffForReconstruction optionsDiff) {
this.fragments = Preconditions.checkNotNull(fragments);
this.optionsDiff = Preconditions.checkNotNull(optionsDiff);
this.hashCode = Objects.hash(fragments, optionsDiff);
}

@VisibleForTesting
Expand Down Expand Up @@ -182,9 +182,6 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
if (hashCode == -1) {
hashCode = Objects.hash(fragments, optionsDiff);
}
return hashCode;
}

Expand Down

0 comments on commit e37a9ab

Please sign in to comment.