Skip to content

Commit

Permalink
Merge branch 'jk/lookup-object-prefer-latest'
Browse files Browse the repository at this point in the history
Optimizes object lookup when the object hashtable starts to become
crowded.

* jk/lookup-object-prefer-latest:
  lookup_object: prioritize recently found objects
  • Loading branch information
Junio C Hamano committed May 29, 2013
2 parents feffa04 + 9a41448 commit 4818cfc
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions object.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,30 @@ static unsigned int hashtable_index(const unsigned char *sha1)

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;
i++;
if (i == obj_hash_size)
i = 0;
}
if (obj && i != first) {
/*
* 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.
*/
struct object *tmp = obj_hash[i];
obj_hash[i] = obj_hash[first];
obj_hash[first] = tmp;
}
return obj;
}

Expand Down

0 comments on commit 4818cfc

Please sign in to comment.