@matheusbsbs / matheus-bagliano / commits / 93e72d8d8f
Fork 0

Preallocate memory earlier in fast-import

I'm about to teach fast-import how to reload the marks file created by a prior session. The general approach that I want to use is to immediately parse the marks file when the specific argument is found in argv, thereby allowing the caller to supply multiple marks files, as the mark space can be sparsely populated. To make that work out we need to allocate our object tables before we parse the command line options. Since none of these tables depend on the command line options, we can easily relocate them. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Mar 7, 2007 at 17:09 UTC 93e72d8d8fbfbbf28abee82c3e769337d7b940ec
1 file changed +6 -8
fast-import.c
+6 -8
@@ -1988,6 +1988,12 @@ int main(int argc, const char **argv)
1988 int i, show_stats = 1;
1989
1990 git_config(git_default_config);
1991 + alloc_objects(object_entry_alloc);
1992 + strbuf_init(&command_buf);
1993 + atom_table = xcalloc(atom_table_sz, sizeof(struct atom_str*));
1994 + branch_table = xcalloc(branch_table_sz, sizeof(struct branch*));
1995 + avail_tree_table = xcalloc(avail_tree_table_sz, sizeof(struct avail_tree_content*));
1996 + marks = pool_calloc(1, sizeof(struct mark_set));
1997
1998 for (i = 1; i < argc; i++) {
1999 const char *a = argv[i];
@@ -2031,14 +2037,6 @@ int main(int argc, const char **argv)
2037 if (i != argc)
2038 usage(fast_import_usage);
2039
2034 - alloc_objects(object_entry_alloc);
2035 - strbuf_init(&command_buf);
2036 -
2037 - atom_table = xcalloc(atom_table_sz, sizeof(struct atom_str*));
2038 - branch_table = xcalloc(branch_table_sz, sizeof(struct branch*));
2039 - avail_tree_table = xcalloc(avail_tree_table_sz, sizeof(struct avail_tree_content*));
2040 - marks = pool_calloc(1, sizeof(struct mark_set));
2041 -
2040 start_packfile();
2041 for (;;) {
2042 read_next_command();