git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 09:05:01 +0200	[thread overview]
Message-ID: <5182101D.4050807@viscovery.net> (raw)
In-Reply-To: <20130502064630.GA15208@sigill.intra.peff.net>

Am 5/2/2013 8:46, schrieb Jeff King:
> 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,

It's absolutely sufficient *if* one reads the commit message. In this
case, though it goes more like "this function should be trivial, and it is
-- up to this if statement; what the heck is it good for?" and the reader
is forced to dig the history.

BTW, do you notice that the function is now modifying an object (the hash
table) even though this is rather unexpected from a "lookup" function?

-- Hannes

  reply	other threads:[~2013-05-02  7:07 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
2013-05-02  7:05     ` Johannes Sixt [this message]
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=5182101D.4050807@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).