Skip to content

Commit 93e72d8

Browse files
committed
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 <[email protected]>
1 parent c390ae9 commit 93e72d8

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

fast-import.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,6 +1988,12 @@ int main(int argc, const char **argv)
19881988
int i, show_stats = 1;
19891989

19901990
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));
19911997

19921998
for (i = 1; i < argc; i++) {
19931999
const char *a = argv[i];
@@ -2031,14 +2037,6 @@ int main(int argc, const char **argv)
20312037
if (i != argc)
20322038
usage(fast_import_usage);
20332039

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-
20422040
start_packfile();
20432041
for (;;) {
20442042
read_next_command();

0 commit comments

Comments
 (0)