From: Johannes Sixt <j.sixt@viscovery.net>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
Duy Nguyen <pclouds@gmail.com>
Subject: Re: [PATCH] lookup_object: prioritize recently found objects
Date: Thu, 02 May 2013 08:44:07 +0200 [thread overview]
Message-ID: <51820B37.8010503@viscovery.net> (raw)
In-Reply-To: <20130501203449.GA12535@sigill.intra.peff.net>
Am 5/1/2013 22:34, schrieb Jeff King:
> 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
next prev parent reply other threads:[~2013-05-02 6:44 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-01 20:34 [PATCH] lookup_object: prioritize recently found objects Jeff King
2013-05-01 21:57 ` Junio C Hamano
2013-05-02 6:44 ` Johannes Sixt [this message]
2013-05-02 6:46 ` Jeff King
2013-05-02 7:05 ` Johannes Sixt
2013-05-02 15:46 ` Junio C Hamano
2013-05-02 15:50 ` Jeff King
2013-05-02 15:46 ` Jeff King
2013-05-03 5:59 ` Johannes Sixt
2013-05-03 6:02 ` Jeff King
2013-05-03 6:16 ` Jeff King
2013-05-02 15:38 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=51820B37.8010503@viscovery.net \
--to=j.sixt@viscovery.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=pclouds@gmail.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 NNTP newsgroup(s).