aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Shreya Bhattarai <shreyax@google.com>2016-05-26 13:46:39 +0000
committerGravatar Yue Gan <yueg@google.com>2016-05-27 08:45:07 +0000
commitfed931d34836400a6a56c857fa10fe7a330ddc10 (patch)
tree49c7ba4416b7d7d1b6f8702f68e2e1f35ab787fe /src
parent09a6a7e3a517342f2347fb40fc52f5f8a45f055b (diff)
Short-circuit equality comparison for unequal PackageIdentifiers by precomputing the hash.
See commit 102a9a101a52f4ca92c9e97387ae159e54e87b05 for Nathan's original investigation into Label interning contention. -- MOS_MIGRATED_REVID=123314470
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java b/src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java
index 2fa4494192..74cd6fa8d7 100644
--- a/src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java
+++ b/src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java
@@ -22,6 +22,7 @@ import com.google.devtools.build.lib.vfs.Canonicalizer;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.io.Serializable;
+import java.util.Objects;
import javax.annotation.concurrent.Immutable;
@@ -77,10 +78,14 @@ public final class PackageIdentifier implements Comparable<PackageIdentifier>, S
/** The name of the package. Canonical (i.e. x.equals(y) <=> x==y). */
private final PathFragment pkgName;
+ /** Precomputed hash code **/
+ private final int hashCode;
+
private PackageIdentifier(RepositoryName repository, PathFragment pkgName) {
this.repository = Preconditions.checkNotNull(repository);
this.pkgName = Canonicalizer.fragments().intern(
Preconditions.checkNotNull(pkgName).normalize());
+ this.hashCode = Objects.hash(repository, pkgName);
}
public static PackageIdentifier parse(String input) throws LabelSyntaxException {
@@ -166,12 +171,13 @@ public final class PackageIdentifier implements Comparable<PackageIdentifier>, S
return false;
}
PackageIdentifier that = (PackageIdentifier) object;
- return pkgName.equals(that.pkgName) && repository.equals(that.repository);
+ return this.hashCode == that.hashCode && pkgName.equals(that.pkgName)
+ && repository.equals(that.repository);
}
@Override
public int hashCode() {
- return 31 * repository.hashCode() + pkgName.hashCode();
+ return this.hashCode;
}
@Override