[PATCH v2] wt-status: avoid repeated insertion for untracked paths
- From
Sahitya Chandra <sahityajb@gmail.com>
- Date
- Jul 17, 2026, 14:46 UTC
- Message-ID
- <20260717144620.259031-1-sahityajb@gmail.com>
- In-Reply-To
- <20260716185045.229320-1-sahityajb@gmail.com>
wt_status_collect_untracked() copies entries from dir.entries and dir.ignored into string_lists using string_list_insert(). That keeps the destination lists sorted and deduplicated, but makes the code harder to reason about because it rebuilds sorted lists through repeated sorted insertion.
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> --- Changes since v1: - Use string_list_sort_u() instead of open-coding sort plus deduplication. - Reword the subject and commit message to avoid overclaiming an O(n^2) cost when the input from fill_directory() is already sorted.
wt-status.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/wt-status.c b/wt-status.c index 58461e02f8..57772c7501 100644 --- a/wt-status.c +++ b/wt-status.c @@ -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); base-commit: 44de1520f08d1dfebc3ab2d9f644208eaa5ac925
-- 2.43.0