wt-status: avoid repeated insertion for untracked paths

wt_status_collect_untracked() copies entries from dir.entries and dir.ignored into string_lists using string_list_insert(). At first glance this seems quadratic, because inserting into the sorted list may shift the backing array, incurring O(n) work for each insert. In practice, though, the entries in the dir struct are already sorted, so we should not have to shift the array and only pay the O(log n) lookup cost for each insertion. But this is subtle and depends on the behavior of fill_directory(). Collect the entries with string_list_append() instead, then sort and deduplicate each list once with string_list_sort_u(). This preserves the sorted, duplicate-free result while making the collection strategy explicit. Signed-off-by: Sahitya Chandra <sahityajb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Sahitya Chandra committed Jul 18, 2026 at 13:44 UTC 7b2648f7454e4d2bfbb78e303ec23d9997e4c985
1 file changed +4 -2
wt-status.c
+4 -2
@@ -832,14 +832,16 @@ static void wt_status_collect_untracked(struct wt_status *s)
832 for (i = 0; i < dir.nr; i++) {
833 struct dir_entry *ent = dir.entries[i];
834 if (index_name_is_other(istate, ent->name, ent->len))
835 - string_list_insert(&s->untracked, ent->name);
835 + string_list_append(&s->untracked, ent->name);
836 }
837 + string_list_sort_u(&s->untracked, 0);
838
839 for (i = 0; i < dir.ignored_nr; i++) {
840 struct dir_entry *ent = dir.ignored[i];
841 if (index_name_is_other(istate, ent->name, ent->len))
841 - string_list_insert(&s->ignored, ent->name);
842 + string_list_append(&s->ignored, ent->name);
843 }
844 + string_list_sort_u(&s->ignored, 0);
845
846 dir_clear(&dir);
847