Skip to content

Commit

Permalink
[7.4.0] Precompute hashcode for RepositoryName. (#23697)
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 676817381
Change-Id: I66b566ed75be858b3f2d92a8ac751bc97358a578

Commit
5949aac

Co-authored-by: Googler <[email protected]>
  • Loading branch information
bazel-io and justinhorvitz authored Sep 20, 2024
1 parent 577a3aa commit 8716f50
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant;
import com.google.devtools.build.lib.util.HashCodes;
import com.google.devtools.build.lib.util.Pair;
import com.google.devtools.build.lib.util.StringCanonicalizer;
import com.google.devtools.build.lib.util.StringUtilities;
Expand Down Expand Up @@ -138,13 +139,18 @@ public static Pair<RepositoryName, PathFragment> fromPathFragment(
*/
@Nullable private final String didYouMeanSuffix;

private final int hashCode;

private RepositoryName(
String name,
@Nullable RepositoryName ownerRepoIfNotVisible,
@Nullable String didYouMeanSuffix) {
this.name = name;
this.ownerRepoIfNotVisible = ownerRepoIfNotVisible;
this.didYouMeanSuffix = didYouMeanSuffix;
this.hashCode =
31 * OsPathPolicy.getFilePathOs().hash(name)
+ HashCodes.hashObjects(ownerRepoIfNotVisible, didYouMeanSuffix);
}

private RepositoryName(String name) {
Expand Down Expand Up @@ -367,7 +373,6 @@ public boolean equals(Object object) {

@Override
public int hashCode() {
return Objects.hash(
OsPathPolicy.getFilePathOs().hash(name), ownerRepoIfNotVisible, didYouMeanSuffix);
return hashCode;
}
}

0 comments on commit 8716f50

Please sign in to comment.