Skip to content

Commit 43e9c4e

Browse files
newrengitster
authored andcommitted
merge-ort: make clear_internal_opts() aware of partial clearing
In order to handle recursive merges, after merging merge-bases we need to clear away most of the data we had built up but some of it needs to be kept -- in particular the "output" field. Rename the function to reflect its future change in use. Further, since "reinitialize" means we'll be reusing the fields immediately, take advantage of this to only partially clear maps, leaving the hashtable allocated and pre-sized. (This may be slightly out-of-order since the speedups aren't realized until there are far more strmaps in use, but the patch submission process already went out of order because of various questions and requests for strmap. Anyway, see commit 6ccdfc2 ("strmap: enable faster clearing and reusing of strmaps", 2020-11-05), for performance details about the use of strmap_partial_clear().) Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4296d8f commit 43e9c4e

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

merge-ort.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,11 @@ static void free_strmap_strings(struct strmap *map)
253253
}
254254
}
255255

256-
static void clear_internal_opts(struct merge_options_internal *opti,
257-
int reinitialize)
256+
static void clear_or_reinit_internal_opts(struct merge_options_internal *opti,
257+
int reinitialize)
258258
{
259-
assert(!reinitialize);
259+
void (*strmap_func)(struct strmap *, int) =
260+
reinitialize ? strmap_partial_clear : strmap_clear;
260261

261262
/*
262263
* We marked opti->paths with strdup_strings = 0, so that we
@@ -266,14 +267,14 @@ static void clear_internal_opts(struct merge_options_internal *opti,
266267
* to deallocate them.
267268
*/
268269
free_strmap_strings(&opti->paths);
269-
strmap_clear(&opti->paths, 1);
270+
strmap_func(&opti->paths, 1);
270271

271272
/*
272273
* All keys and values in opti->conflicted are a subset of those in
273274
* opti->paths. We don't want to deallocate anything twice, so we
274275
* don't free the keys and we pass 0 for free_values.
275276
*/
276-
strmap_clear(&opti->conflicted, 0);
277+
strmap_func(&opti->conflicted, 0);
277278

278279
/*
279280
* opti->paths_to_free is similar to opti->paths; we created it with
@@ -1344,7 +1345,7 @@ void merge_finalize(struct merge_options *opt,
13441345

13451346
assert(opt->priv == NULL);
13461347

1347-
clear_internal_opts(opti, 0);
1348+
clear_or_reinit_internal_opts(opti, 0);
13481349
FREE_AND_NULL(opti);
13491350
}
13501351

0 commit comments

Comments
 (0)