git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] lookup_object: prioritize recently found objects

From
Jeff King <peff@peff.net>
Date
May 2, 2013, 06:46 UTC
Message-ID
<20130502064630.GA15208@sigill.intra.peff.net>
In-Reply-To
<51820B37.8010503@viscovery.net>
On Thu, May 02, 2013 at 08:44:07AM +0200, Johannes Sixt wrote:
Show 30 quoted lines
> 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
Previous: Johannes SixtNext: Johannes Sixt
Message 4 of 12 in “lookup_object: prioritize recently found objects”
  1. lookup_object: prioritize recently found objectsJeff King, May 1, 2013
  2. Junio C HamanoMay 1, 2013
  3. Johannes SixtMay 2, 2013
  4. Jeff KingMay 2, 2013
  5. Johannes SixtMay 2, 2013
  6. Junio C HamanoMay 2, 2013
  7. Jeff KingMay 2, 2013
  8. Jeff KingMay 2, 2013
  9. Johannes SixtMay 3, 2013
  10. Jeff KingMay 3, 2013
  11. Jeff KingMay 3, 2013
  12. Junio C HamanoMay 2, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.