git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Johannes Sixt <j.sixt@viscovery.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, 2 May 2013 02:46:30 -0400	[thread overview]
Message-ID: <20130502064630.GA15208@sigill.intra.peff.net> (raw)
In-Reply-To: <51820B37.8010503@viscovery.net>

On Thu, May 02, 2013 at 08:44:07AM +0200, Johannes Sixt wrote:

> 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:

I figured the lengthy description in the commit message would be
sufficient, but I don't mind adding something like your suggestion to
point readers of the code in the right direction when they see it.

-Peff

  reply	other threads:[~2013-05-02  6:46 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
2013-05-02  6:46   ` Jeff King [this message]
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=20130502064630.GA15208@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j.sixt@viscovery.net \
    --cc=pclouds@gmail.com \
    /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).