diff options
author | Eric Fellheimer <felly@google.com> | 2015-11-13 22:11:10 +0000 |
---|---|---|
committer | Damien Martin-Guillerez <dmarting@google.com> | 2015-11-16 09:02:20 +0000 |
commit | b503be7b2e2e6a1601bff3790e6e292ff9076359 (patch) | |
tree | 49363adb352d670532f75d3c24cf9c2564453663 | |
parent | 110b065bf7b53db9d5821323a4bd9dc9b127b244 (diff) |
Optimize the hash code function of Pair to minimize varargs expansion.
--
MOS_MIGRATED_REVID=107812527
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/util/Pair.java | 4 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/util/PairTest.java | 4 |
2 files changed, 4 insertions, 4 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/util/Pair.java b/src/main/java/com/google/devtools/build/lib/util/Pair.java index 08f1e798f0..91d04c62f1 100644 --- a/src/main/java/com/google/devtools/build/lib/util/Pair.java +++ b/src/main/java/com/google/devtools/build/lib/util/Pair.java @@ -81,7 +81,9 @@ public final class Pair<A, B> { @Override public int hashCode() { - return Objects.hash(first, second); + int hash1 = first == null ? 0 : first.hashCode(); + int hash2 = second == null ? 0 : second.hashCode(); + return 31 * hash1 + hash2; } /** diff --git a/src/test/java/com/google/devtools/build/lib/util/PairTest.java b/src/test/java/com/google/devtools/build/lib/util/PairTest.java index a54b256da5..98bebbc867 100644 --- a/src/test/java/com/google/devtools/build/lib/util/PairTest.java +++ b/src/test/java/com/google/devtools/build/lib/util/PairTest.java @@ -21,8 +21,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import java.util.Objects; - /** * Tests for {@link Pair}. */ @@ -37,7 +35,7 @@ public class PairTest { assertSame(a, p.first); assertSame(b, p.second); assertEquals(Pair.of(a, b), p); - assertEquals(Objects.hash(a, b), p.hashCode()); + assertEquals(31 * a.hashCode() + b.hashCode(), p.hashCode()); } @Test |