threads / patch / 35089

patchdiffcore-delta: optimize renames and copies detection (git diff -M/-C)

Subject: [PATCH] diffcore-delta: optimize renames and copies detection (git diff -M/-C)

## tl;dr

One message between Oct 9, 2013 and Oct 9, 2013. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Yoshioka Tsuneo· Oct 9, 2013, 10:27 UTC · lore

diffcore_count_changes() can return -1 when src_copied is greater than delta_limit, without counting all the src_copied. By that, performance of "diff -M/-C" can be improved.

Signed-off-by: Tsuneo Yoshioka <yoshiokatsuneo@gmail.com>
---
 diffcore-delta.c  | 11 ++++++++---
 diffcore-rename.c |  2 +-
 2 files changed, 9 insertions(+), 4 deletions(-)
Show changes to 2 files +9 −4

diffcore-delta.c, diffcore-rename.c

diff --git a/diffcore-delta.c b/diffcore-delta.c
index 7cf431d..0a9290e 100644
--- a/diffcore-delta.c
+++ b/diffcore-delta.c
@@ -173,7 +173,7 @@ int diffcore_count_changes(struct diff_filespec *src,
 {
 	struct spanhash *s, *d;
 	struct spanhash_top *src_count, *dst_count;
-	unsigned long sc, la;
+	unsigned long sc, not_sc, la;
 
 	src_count = dst_count = NULL;
 	if (src_count_p)
@@ -190,7 +190,7 @@ int diffcore_count_changes(struct diff_filespec *src,
 		if (dst_count_p)
 			*dst_count_p = dst_count;
 	}
-	sc = la = 0;
+	sc = not_sc = la = 0;
 
 	s = src_count->data;
 	d = dst_count->data;
@@ -214,8 +214,13 @@ int diffcore_count_changes(struct diff_filespec *src,
 			la += dst_cnt - src_cnt;
 			sc += src_cnt;
 		}
-		else
+		else{
 			sc += dst_cnt;
+			not_sc += (src_cnt - dst_cnt);
+			if(delta_limit != 0 && not_sc > delta_limit){
+				return -1;
+			}
+		}
 		s++;
 	}
 	while (d->cnt) {
diff --git a/diffcore-rename.c b/diffcore-rename.c
index 6c7a72f..d52b2c8 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -181,7 +181,7 @@ static int estimate_similarity(struct diff_filespec *src,
 		return 0;
 
 	delta_limit = (unsigned long)
-		(base_size * (MAX_SCORE-minimum_score) / MAX_SCORE);
+		(max_size * (MAX_SCORE-minimum_score) / MAX_SCORE);
 	if (diffcore_count_changes(src, dst,
 				   &src->cnt_data, &dst->cnt_data,
 				   delta_limit,
-- 
1.7.12.4 (Apple Git-37)

← back to recent threads