[EGIT PATCH 09/10] Hash ObjectId faster.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



ObjectId's are well distributed so we can grab the first four bytes
as the hash code. The assumption makes hashing faster.

Signed-off-by: Robin Rosenberg <robin.rosenberg@xxxxxxxxxx>
---

 .../src/org/spearce/jgit/lib/ObjectId.java         |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectId.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectId.java
index 9e62424..45e23e6 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectId.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectId.java
@@ -163,12 +163,13 @@ public class ObjectId implements Comparable {
 	}
 
 	public int hashCode() {
-		int r = 0;
-		for (int k = id.length - 1; k >= 0; k--) {
-			r *= 31;
-			r += id[k];
-		}
-		return r;
+		// Object Id' are well distributed so grab the first four bytes
+		int b0 = id[0] & 0xff;
+		int b1 = id[1] & 0xff;
+		int b2 = id[2] & 0xff;
+		int b3 = id[3] & 0xff;
+		int h = (b0 << 24) | (b1 << 16) | (b2 << 8) | b3;
+		return h;
 	}
 
 	public boolean equals(final ObjectId o) {

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]