Re: [PATCH 08/12] merge-ort: provide a merge_get_conflicted_files() helper function
- From
Christian Couder <christian.couder@gmail.com>
- Date
- Jan 26, 2022, 11:07 UTC
- Message-ID
- <CAP8UFD0iQg4nL6eSTDbEu8t6h+K0H+nGF8y_N0z3XyjH+KGORA@mail.gmail.com>
- In-Reply-To
- <35e0ed9271a0229fe2acd2385a7e4171d4dfe077.1642888562.git.gitgitgadget@gmail.com>
On Sat, Jan 22, 2022 at 10:56 PM Elijah Newren via GitGitGadget <gitgitgadget@gmail.com> wrote:
Show 21 quoted lines
> +void merge_get_conflicted_files(struct merge_result *result,
> + struct string_list *conflicted_files)
> +{
> + struct hashmap_iter iter;
> + struct strmap_entry *e;
> + struct merge_options_internal *opti = result->priv;
> +
> + strmap_for_each_entry(&opti->conflicted, &iter, e) {
> + const char *path = e->key;
> + struct conflict_info *ci = e->value;
> + int i;
> +
> + VERIFY_CI(ci);
> +
> + for (i = MERGE_BASE; i <= MERGE_SIDE2; i++) {
> + struct stage_info *si;
> +
> + if (!(ci->filemask & (1ul << i)))
> + continue;
> +
> + si = xmalloc(sizeof(*si));It's probably a premature optimization, so feel free to ignore, but as MERGE_BASE and MERGE_SIDE2 are constants, and ci->filemask is constant inside the 'for' loop, we could compute before the 'for' loop how many 'struct stage_info' we will need and allocate them all at once before the 'for' loop.
Show 9 quoted lines
> + si->stage = i+1; > + si->mode = ci->stages[i].mode; > + oidcpy(&si->oid, &ci->stages[i].oid); > + string_list_append(conflicted_files, path)->util = si; > + } > + } > + /* string_list_sort() uses a stable sort, so we're good */ > + string_list_sort(conflicted_files); > +}