changeset 30439:5c4e2636c1a9

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.
author Mads Kiilerich <madski@unity3d.com>
date Tue, 08 Nov 2016 18:37:33 +0100
parents 38ed54888617
children 8c0c75aa3ff4
files mercurial/bdiff.c
diffstat 1 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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;
+				}
 			}
 		}
 	}