]> git.ipfire.org Git - thirdparty/git.git/commitdiff
wt-status: avoid repeated insertion for untracked paths
authorSahitya Chandra <sahityajb@gmail.com>
Sat, 18 Jul 2026 08:14:49 +0000 (13:44 +0530)
committerJunio C Hamano <gitster@pobox.com>
Sun, 19 Jul 2026 23:21:33 +0000 (16:21 -0700)
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>
wt-status.c

index 58461e02f886ae17555334cb7e2695834078a03e..57772c7501fdbab71fe1dd621ce719eabc22acdf 100644 (file)
@@ -832,14 +832,16 @@ static void wt_status_collect_untracked(struct wt_status *s)
        for (i = 0; i < dir.nr; i++) {
                struct dir_entry *ent = dir.entries[i];
                if (index_name_is_other(istate, ent->name, ent->len))
-                       string_list_insert(&s->untracked, ent->name);
+                       string_list_append(&s->untracked, ent->name);
        }
+       string_list_sort_u(&s->untracked, 0);
 
        for (i = 0; i < dir.ignored_nr; i++) {
                struct dir_entry *ent = dir.ignored[i];
                if (index_name_is_other(istate, ent->name, ent->len))
-                       string_list_insert(&s->ignored, ent->name);
+                       string_list_append(&s->ignored, ent->name);
        }
+       string_list_sort_u(&s->ignored, 0);
 
        dir_clear(&dir);