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

[PATCH 1/1] diffcore-rename: speed up register_rename_src

From
JGJeff Hostetler via GitGitGadget <gitgitgadget@gmail.com>
Date
Jun 8, 2019, 14:42 UTC
Message-ID
<4ac75dd3635e39f9faa67fb1e88897663e3dc6cd.1560004960.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.142.git.gitgitgadget@gmail.com>
From: Jeff Hostetler <jeffhost@microsoft.com>

Teach register_rename_src() to see if new file pair can simply be appended to the rename_src[] array before performing the binary search to find the proper insertion point.

This is a performance optimization. This routine is called during run_diff_files in status and the caller is iterating over the sorted index, so we should expect to be able to append in the normal case. The existing insert logic is preserved so we don't have to assume that, but simply take advantage of it if possible.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 diffcore-rename.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
diff --git a/diffcore-rename.c b/diffcore-rename.c
index 07bd34b631..5bfc5f6c22 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -82,6 +82,18 @@ static struct diff_rename_src *register_rename_src(struct diff_filepair *p)
 
 	first = 0;
 	last = rename_src_nr;
+
+	if (last > 0) {
+		struct diff_rename_src *src = &(rename_src[last-1]);
+		int cmp = strcmp(one->path, src->p->one->path);
+		if (!cmp)
+			return src;
+		if (cmp > 0) {
+			first = last;
+			goto append_it;
+		}
+	}
+
 	while (last > first) {
 		int next = (last + first) >> 1;
 		struct diff_rename_src *src = &(rename_src[next]);
@@ -95,6 +107,7 @@ static struct diff_rename_src *register_rename_src(struct diff_filepair *p)
 		first = next+1;
 	}
 
+append_it:
 	/* insert to make it at "first" */
 	ALLOC_GROW(rename_src, rename_src_nr + 1, rename_src_alloc);
 	rename_src_nr++;
-- 
gitgitgadget
Previous: Johannes Schindelin via GitGitGadgetNext: René Scharfe
Message 2 of 7 in “Optimize run_diff_files()' rename detection”
  1. 0/1 Optimize run_diff_files()' rename detectionJohannes Schindelin via GitGitGadget, Jun 8, 2019
  2. 1/1 diffcore-rename: speed up register_rename_srcJeff Hostetler via GitGitGadget, Jun 8, 2019
  3. René ScharfeJun 8, 2019
  4. Jeff HostetlerJun 10, 2019
  5. SZEDER GáborJun 10, 2019
  6. Jeff HostetlerJun 10, 2019
  7. Jeff HostetlerJun 10, 2019

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.