Git development
 help / color / mirror / Atom feed
From: Sahitya Chandra <sahityajb@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, avarab@gmail.com, stolee@gmail.com,
	peff@peff.net, ps@pks.im, Sahitya Chandra <sahityajb@gmail.com>
Subject: [PATCH v3] wt-status: avoid repeated insertion for untracked paths
Date: Sat, 18 Jul 2026 13:44:49 +0530	[thread overview]
Message-ID: <20260718081449.26747-1-sahityajb@gmail.com> (raw)
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

  parent reply	other threads:[~2026-07-18  8:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-16 18:50 [PATCH] wt-status: avoid quadratic insertion for untracked paths Sahitya Chandra
2026-07-17  6:27 ` Patrick Steinhardt
2026-07-17  7:54   ` Jeff King
2026-07-17 14:40     ` Sahitya Chandra
2026-07-17 14:37   ` Sahitya Chandra
2026-07-17 14:46 ` [PATCH v2] wt-status: avoid repeated " Sahitya Chandra
2026-07-18  7:31   ` Jeff King
2026-07-18  8:05     ` Sahitya Chandra
2026-07-18  8:14   ` Sahitya Chandra [this message]
2026-07-18  8:38     ` [PATCH v3] " Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260718081449.26747-1-sahityajb@gmail.com \
    --to=sahityajb@gmail.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    --cc=ps@pks.im \
    --cc=stolee@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox