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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 diffcore-delta.c  | 11 ++++++++---
 diffcore-rename.c |  2 +-
 2 files changed, 9 insertions(+), 4 deletions(-)

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)


--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]