# HG changeset patch
# User Mads Kiilerich <mad...@unity3d.com>
# Date 1478208837 -3600
#      Thu Nov 03 22:33:57 2016 +0100
# Node ID a3e3c7075c3c4b92e6b8c27e28bef7b2c061008d
# Parent  c593308da04e9144da01a08401d886a64985c74b
bdiff: rearrange the better longest match code

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.

diff --git a/mercurial/bdiff.c b/mercurial/bdiff.c
--- a/mercurial/bdiff.c
+++ b/mercurial/bdiff.c
@@ -172,10 +172,20 @@ static int longest_match(struct bdiff_li
 
                        /* 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 is always better */
                                mi = i;
                                mj = j;
                                mk = k;
+                       } else if (k == mk) {
+                               if (i > mi && i <= half) {
+                                       /* better i in first lower half */
+                                       mi = i;
+                                       mj = j;
+                               } else if (i == mi) {
+                                       /* an earlier j is "better" */
+                                       mj = j;
+                               }
                        }
                }
        }
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to