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 6ccdfc2a20 ("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 <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Dec 16, 2020 at 22:28 UTC 43e9c4eeccc069dbe6ca8a65dc5d0093b46acc03
1 file changed +7 -6
merge-ort.c
+7 -6
@@ -253,10 +253,11 @@ static void free_strmap_strings(struct strmap *map)
253 }
254 }
255
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)
258 {
259 - assert(!reinitialize);
259 + void (*strmap_func)(struct strmap *, int) =
260 + reinitialize ? strmap_partial_clear : strmap_clear;
261
262 /*
263 * 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,
267 * to deallocate them.
268 */
269 free_strmap_strings(&opti->paths);
269 - strmap_clear(&opti->paths, 1);
270 + strmap_func(&opti->paths, 1);
271
272 /*
273 * All keys and values in opti->conflicted are a subset of those in
274 * opti->paths. We don't want to deallocate anything twice, so we
275 * don't free the keys and we pass 0 for free_values.
276 */
276 - strmap_clear(&opti->conflicted, 0);
277 + strmap_func(&opti->conflicted, 0);
278
279 /*
280 * opti->paths_to_free is similar to opti->paths; we created it with
@@ -1344,7 +1345,7 @@ void merge_finalize(struct merge_options *opt,
1345
1346 assert(opt->priv == NULL);
1347
1347 - clear_internal_opts(opti, 0);
1348 + clear_or_reinit_internal_opts(opti, 0);
1349 FREE_AND_NULL(opti);
1350 }
1351