From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 946F21F44D for ; Mon, 25 Mar 2024 05:33:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1711344795; bh=nNn4y1vfdEoCgMXTm8uYD0yE9D7HVhZBaMFrtFjJHNg=; h=From:To:Subject:Date:From; b=psQcfRk5ky1Z0fi7l8EImw0zbHTIn6z9ZlKgsN+KwO3bjW6BjVlGrhPjXgpbRo5FG AWBepFijmtbCXMXXJ5Dkrhxm0+H4UuLqm1ESpE6vg2wyYKy2KwQTIFxZJzqkqaFDYR Vd78X6PpFpYhJzn6VqgpfxveIxIy1l/6K8/hC4mI= From: Eric Wong To: spew@80x24.org Subject: [PATCH] no branch Date: Mon, 25 Mar 2024 05:33:15 +0000 Message-ID: <20240325053315.3393197-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: --- 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) { /*