@matheusbsbs / matheus-bagliano / commits / 2fce1f3c86
Fork 0

Optimize index creation on large object sets in fast-import.

When we are generating multiple packfiles at once we only need to scan the blocks of object_entry structs which contain objects for the current packfile. Because the most recent blocks are at the front of the linked list, and because all new objects going into the current file are allocated from the front of that list, we can stop scanning for objects as soon as we identify one which doesn't belong to the current packfile. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Jan 15, 2007 at 06:51 UTC 2fce1f3c862845d23b2bd8305f97abb115623192
1 file changed +8 -3
fast-import.c
+8 -3
@@ -678,10 +678,15 @@ static void write_index(const char *idx_name)
678 idx = xmalloc(object_count * sizeof(struct object_entry*));
679 c = idx;
680 for (o = blocks; o; o = o->next_pool)
681 - for (e = o->entries; e != o->next_free; e++)
682 - if (pack_id == e->pack_id)
683 - *c++ = e;
681 + for (e = o->next_free; e-- != o->entries;) {
682 + if (pack_id != e->pack_id)
683 + goto sort_index;
684 + *c++ = e;
685 + }
686 +sort_index:
687 last = idx + object_count;
688 + if (c != last)
689 + die("internal consistency error creating the index");
690 qsort(idx, object_count, sizeof(struct object_entry*), oecmp);
691
692 /* Generate the fan-out array. */