dumping ground for random patches and texts
 help / color / mirror / Atom feed
* [PATCH] no branch
@ 2024-03-25  5:33 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2024-03-25  5:33 UTC (permalink / raw)
  To: spew

---
 object.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/object.c b/object.c
index 4219da9e3b..0224712a1c 100644
--- a/object.c
+++ b/object.c
@@ -74,12 +74,10 @@ static unsigned int hash_obj(const struct object_id *oid, unsigned int n)
 static void insert_obj_hash(struct object *obj, struct object **hash, unsigned int size)
 {
 	unsigned int j = hash_obj(&obj->oid, size);
+	unsigned int mask = size - 1;
 
-	while (hash[j]) {
-		j++;
-		if (j >= size)
-			j = 0;
-	}
+	while (hash[j])
+		j = (j + 1) & mask;
 	hash[j] = obj;
 }
 
@@ -89,19 +87,18 @@ static void insert_obj_hash(struct object *obj, struct object **hash, unsigned i
  */
 struct object *lookup_object(struct repository *r, const struct object_id *oid)
 {
-	unsigned int i, first;
+	unsigned int i, first, mask;
 	struct object *obj;
 
 	if (!r->parsed_objects->obj_hash)
 		return NULL;
 
 	first = i = hash_obj(oid, r->parsed_objects->obj_hash_size);
+	mask = r->parsed_objects->obj_hash_size - 1;
 	while ((obj = r->parsed_objects->obj_hash[i]) != NULL) {
 		if (oideq(oid, &obj->oid))
 			break;
-		i++;
-		if (i == r->parsed_objects->obj_hash_size)
-			i = 0;
+		i = (i + 1) & mask;
 	}
 	if (obj && i != first) {
 		/*

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2024-03-25  5:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-25  5:33 [PATCH] no branch Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).