Subject: [PATCH 05/11] object hash: we know the table size is a power of two

From: Junio C Hamano <[email-masked]>
Date: Thu, 11 Aug 2011 10:53:10 -0700

Signed-off-by: Junio C Hamano <[email-masked]>
---
 object.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/object.c b/object.c
index 259a67e..d95d7a6 100644
--- a/object.c
+++ b/object.c
@@ -52,7 +52,7 @@ static unsigned int hash_val(const unsigned char *sha1)
 
 static void insert_obj_hash(struct object *obj, struct object **hash, unsigned int size)
 {
-	unsigned int j = hash_val(obj->sha1) % size;
+	unsigned int j = hash_val(obj->sha1) & (size-1);
 
 	while (hash[j]) {
 		j++;
@@ -70,7 +70,7 @@ struct object *lookup_object(const unsigned char *sha1)
 	if (!obj_hash)
 		return NULL;
 
-	i = hash_val(sha1) % obj_hash_size;
+	i = hash_val(sha1) & (obj_hash_size-1);
 	while ((obj = obj_hash[i]) != NULL) {
 		if (!hashcmp(sha1, obj->sha1))
 			break;
-- 
1.7.6.433.g1421f