Patchwork [3,of,6,STABLE] bdiff: fold in shift calculation in normalize

login
register
mail settings
Submitter Matt Mackall
Date April 23, 2016, 3:41 p.m.
Message ID <48c7e086444c9dc7a80f.1461426076@ruin.waste.org>
Download mbox | patch
Permalink /patch/14771/
State Superseded
Commit 8bcda4c76820c620941a11a4802be0015d7ecb23
Headers show

Comments

Matt Mackall - April 23, 2016, 3:41 p.m.
# HG changeset patch
# User Matt Mackall <mpm@selenic.com>
# Date 1461293191 18000
#      Thu Apr 21 21:46:31 2016 -0500
# Branch stable
# Node ID 48c7e086444c9dc7a80fa3d24b282ad345c07a33
# Parent  f2310bbf12db65ebf1c9e150ae784fa2ef630c26
bdiff: fold in shift calculation in normalize

This just makes the code harder to read without any performance
advantage. We're going to make the check here more complex, let's make
it simpler first.

Patch

diff -r f2310bbf12db -r 48c7e086444c mercurial/bdiff.c
--- a/mercurial/bdiff.c	Thu Apr 21 21:37:13 2016 -0500
+++ b/mercurial/bdiff.c	Thu Apr 21 21:46:31 2016 -0500
@@ -259,22 +259,18 @@ 
 	/* normalize the hunk list, try to push each hunk towards the end */
 	for (curr = base->next; curr; curr = curr->next) {
 		struct hunk *next = curr->next;
-		int shift = 0;
 
 		if (!next)
 			break;
 
 		if (curr->a2 == next->a1 || curr->b2 == next->b1)
-			while (curr->a2 + shift < an && curr->b2 + shift < bn
-			       && !cmp(a + curr->a2 + shift,
-				       b + curr->b2 + shift))
-				shift++;
-		if (!shift)
-			continue;
-		curr->b2 += shift;
-		next->b1 += shift;
-		curr->a2 += shift;
-		next->a1 += shift;
+			while (curr->a2 < an && curr->b2 < bn
+			       && !cmp(a + curr->a2, b + curr->b2)) {
+				curr->a2++;
+				next->a1++;
+				curr->b2++;
+				next->b1++;
+			}
 	}
 
 	for (curr = base->next; curr; curr = curr->next)