Skip to content

Commit

Permalink
fast-import: insert new object entries at start of hash bucket
Browse files Browse the repository at this point in the history
More often than not, find_object is called for recently inserted objects.
Optimise for this case by inserting new entries at the start of the chain.
This doesn't affect the cost of new inserts but reduces the cost of find
and insert for existing object entries.

Signed-off-by: David Barr <david.barr@cordelta.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
David Barr authored and Junio C Hamano committed Nov 24, 2010
1 parent 593ce2b commit b7c1ce4
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions fast-import.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,22 +539,17 @@ static struct object_entry *insert_object(unsigned char *sha1)
{
unsigned int h = sha1[0] << 8 | sha1[1];
struct object_entry *e = object_table[h];
struct object_entry *p = NULL;

while (e) {
if (!hashcmp(sha1, e->idx.sha1))
return e;
p = e;
e = e->next;
}

e = new_object(sha1);
e->next = NULL;
e->next = object_table[h];
e->idx.offset = 0;
if (p)
p->next = e;
else
object_table[h] = e;
object_table[h] = e;
return e;
}

Expand Down

0 comments on commit b7c1ce4

Please sign in to comment.