fast-import: insert new object entries at start of hash bucket
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>
David Barr committed
Nov 23, 2010 at 01:53 UTC
b7c1ce4f14f37600a8a5bf8d81e0a723d42644b9
1 file changed
+2
-7
fast-import.c
+2
-7
@@ -539,22 +539,17 @@ static struct object_entry *insert_object(unsigned char *sha1)
539
{
540
unsigned int h = sha1[0] << 8 | sha1[1];
541
struct object_entry *e = object_table[h];
542
- struct object_entry *p = NULL;
542
543
while (e) {
544
if (!hashcmp(sha1, e->idx.sha1))
545
return e;
547
- p = e;
546
e = e->next;
547
}
548
549
e = new_object(sha1);
552
- e->next = NULL;
550
+ e->next = object_table[h];
551
e->idx.offset = 0;
554
- if (p)
555
- p->next = e;
556
- else
557
- object_table[h] = e;
552
+ object_table[h] = e;
553
return e;
554
}
555