bdiff: rearrange the "better longest match" code
authorMads Kiilerich <madski@unity3d.com>
Tue, 08 Nov 2016 18:37:33 +0100
changeset 30430 5c4e2636c1a9
parent 30429 38ed54888617
child 30431 8c0c75aa3ff4
bdiff: rearrange the "better longest match" code This is primarily to make the code more managable and prepare for later changes. More specific assignments might also be slightly faster, even thought it also might generate a bit more code.
mercurial/bdiff.c
--- a/mercurial/bdiff.c	Tue Nov 08 18:37:33 2016 +0100
+++ b/mercurial/bdiff.c	Tue Nov 08 18:37:33 2016 +0100
@@ -177,10 +177,20 @@
 
 			/* best match so far? we prefer matches closer
 			   to the middle to balance recursion */
-			if (k > mk || (k == mk && (i <= mi || i <= half))) {
+			if (k > mk) {
+				/* a longer match */
 				mi = i;
 				mj = j;
 				mk = k;
+			} else if (k == mk) {
+				if (i > mi && i <= half) {
+					/* same match but closer to half */
+					mi = i;
+					mj = j;
+				} else if (i == mi) {
+					/* same i but earlier j */
+					mj = j;
+				}
 			}
 		}
 	}