git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3] wt-status: avoid repeated insertion for untracked paths

From
Sahitya Chandra <sahityajb@gmail.com>
Date
Jul 18, 2026, 08:14 UTC
Message-ID
<20260718081449.26747-1-sahityajb@gmail.com>
In-Reply-To
<20260717144620.259031-1-sahityajb@gmail.com>

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>
---
Changes since v2:
- Reword the commit message to explain the quadratic concern while noting
  that the current sorted input avoids array shifts in practice.
 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: 41365c2a9ba347870b80881c0d67454edd22fd49
-- 
2.43.0
Previous: Sahitya ChandraNext: Jeff King
Message 9 of 10 in “wt-status: avoid quadratic insertion for untracked paths”
  1. wt-status: avoid quadratic insertion for untracked pathsSahitya Chandra, Jul 16, 2026
  2. Patrick SteinhardtJul 17, 2026
  3. Jeff KingJul 17, 2026
  4. Sahitya ChandraJul 17, 2026
  5. Sahitya ChandraJul 17, 2026
  6. wt-status: avoid repeated insertion for untracked pathsSahitya Chandra, Jul 17, 2026
  7. Jeff KingJul 18, 2026
  8. Sahitya ChandraJul 18, 2026
  9. wt-status: avoid repeated insertion for untracked pathsSahitya Chandra, Jul 18, 2026
  10. Jeff KingJul 18, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.