Skip to content

Commit b7c1ce4

Browse files
barrbraingitster
authored andcommitted
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 <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 593ce2b commit b7c1ce4

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

fast-import.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -539,22 +539,17 @@ static struct object_entry *insert_object(unsigned char *sha1)
539539
{
540540
unsigned int h = sha1[0] << 8 | sha1[1];
541541
struct object_entry *e = object_table[h];
542-
struct object_entry *p = NULL;
543542

544543
while (e) {
545544
if (!hashcmp(sha1, e->idx.sha1))
546545
return e;
547-
p = e;
548546
e = e->next;
549547
}
550548

551549
e = new_object(sha1);
552-
e->next = NULL;
550+
e->next = object_table[h];
553551
e->idx.offset = 0;
554-
if (p)
555-
p->next = e;
556-
else
557-
object_table[h] = e;
552+
object_table[h] = e;
558553
return e;
559554
}
560555

0 commit comments

Comments
 (0)