On Sat, Jan 22, 2022 at 10:56 PM Elijah Newren via GitGitGadget <gitgitgadget@xxxxxxxxx> wrote: > +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. > + 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); > +}