Re: [PATCH] lookup_object: prioritize recently found objects
- From
Johannes Sixt <j.sixt@viscovery.net>
- Date
- May 2, 2013, 06:44 UTC
- Message-ID
- <51820B37.8010503@viscovery.net>
- In-Reply-To
- <20130501203449.GA12535@sigill.intra.peff.net>
Am 5/1/2013 22:34, schrieb Jeff King:
Show 25 quoted lines
> struct object *lookup_object(const unsigned char *sha1)
> {
> - unsigned int i;
> + unsigned int i, first;
> struct object *obj;
>
> if (!obj_hash)
> return NULL;
>
> - i = hashtable_index(sha1);
> + first = i = hashtable_index(sha1);
> while ((obj = obj_hash[i]) != NULL) {
> if (!hashcmp(sha1, obj->sha1))
> break;
> @@ -85,6 +85,11 @@ struct object *lookup_object(const unsigned char *sha1)
> if (i == obj_hash_size)
> i = 0;
> }
> + if (obj && i != first) {
> + struct object *tmp = obj_hash[i];
> + obj_hash[i] = obj_hash[first];
> + obj_hash[first] = tmp;
> + }
> return obj;
> }This is one of the places where I think the code does not speak for itself and a comment is warranted: The new if statement is not about correctness, but about optimization:
/* * Move object to where we started to look for it * so that we do not need to walk the hash table * the next time we look for it. */
or something.
-- Hannes