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

[PATCH] fast-import: use binary search in tree_content_remove

From
Jeff King <peff@peff.net>
Date
Mar 10, 2007, 19:40 UTC
Message-ID
<20070310194012.GA5126@coredump.intra.peff.net>
In-Reply-To
<20070310192304.GB3416@coredump.intra.peff.net>
Signed-off-by: Jeff King <peff@peff.net>
---
> I should note that this patch doesn't handle removing entries from
> tree_content structs; I will work up a patch for that momentarily.

And here it is. However, I should note that this patch is _not_ necessary. I had originally thought that removal might destroy the sorting that I added in the last patch, but it looks like the entry isn't actually removed. Shawn, can you sanity check this?

This patch still has value, though, because it improves performance when deleting entries from a large tree (I just didn't do that in my test case, so it wasn't a problem before).

 fast-import.c |   33 +++++++++++++++++----------------
 1 files changed, 17 insertions(+), 16 deletions(-)
diff --git a/fast-import.c b/fast-import.c
index 4cd01ee..4322216 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -1295,6 +1295,7 @@ static int tree_content_remove(struct tree_entry *root, const char *p)
 	const char *slash1;
 	unsigned int i, n;
 	struct tree_entry *e;
+	struct atom_str *name;
 
 	slash1 = strchr(p, '/');
 	if (slash1)
@@ -1302,24 +1303,24 @@ static int tree_content_remove(struct tree_entry *root, const char *p)
 	else
 		n = strlen(p);
 
-	for (i = 0; i < t->entry_count; i++) {
-		e = t->entries[i];
-		if (e->name->str_len == n && !strncmp(p, e->name->str_dat, n)) {
-			if (!slash1 || !S_ISDIR(e->versions[1].mode))
-				goto del_entry;
-			if (!e->tree)
-				load_tree(e);
-			if (tree_content_remove(e, slash1 + 1)) {
-				for (n = 0; n < e->tree->entry_count; n++) {
-					if (e->tree->entries[n]->versions[1].mode) {
-						hashclr(root->versions[1].sha1);
-						return 1;
-					}
-				}
-				goto del_entry;
+	name = to_atom(p, n);
+	i = find_tree_entry(t, name);
+	if(i == -1)
+		return 0;
+	e = t->entries[i];
+
+	if (!slash1 || !S_ISDIR(e->versions[1].mode))
+		goto del_entry;
+	if (!e->tree)
+		load_tree(e);
+	if (tree_content_remove(e, slash1 + 1)) {
+		for (n = 0; n < e->tree->entry_count; n++) {
+			if (e->tree->entries[n]->versions[1].mode) {
+				hashclr(root->versions[1].sha1);
+				return 1;
 			}
-			return 0;
 		}
+		goto del_entry;
 	}
 	return 0;
 
-- 
1.5.0.3.931.g55c05
Previous: Jeff KingNext: Shawn O. Pearce
Message 10 of 15 in “fast-import slow on large directories”
  1. 0/3 fast-import slow on large directoriesJeff King, Mar 10, 2007
  2. 1/3 fast-import: grow tree storage more aggressivelyJeff King, Mar 10, 2007
  3. 2/3 fast-import: tree allocation cleanupsJeff King, Mar 10, 2007
  4. Shawn O. PearceMar 11, 2007
  5. Jeff KingMar 11, 2007
  6. Jeff KingMar 11, 2007
  7. Shawn O. PearceMar 12, 2007
  8. 3/3 fast-import: improve efficiency of tree_content_setJeff King, Mar 10, 2007
  9. Jeff KingMar 10, 2007
  10. fast-import: use binary search in tree_content_removeJeff King, Mar 10, 2007
  11. Shawn O. PearceMar 11, 2007
  12. Jeff KingMar 11, 2007
  13. Jeff KingMar 11, 2007
  14. Shawn O. PearceMar 11, 2007
  15. Shawn O. PearceMar 12, 2007

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.