Mercurial > public > mercurial-scm > hg-stable
diff mercurial/bdiff.c @ 30440:8c0c75aa3ff4
bdiff: give slight preference to longest matches in the middle of the B side
We already have a slight preference for matches close to the middle on the A
side. Now, do the same on the B side.
j is iterating the b range backwards and we thus accept a new j if the previous
match was in the upper half.
This makes the test-bhalf diff "correct". It obviously also gives more
preference to balanced recursion than to appending to sequences. That is kind
of correct, but will also unfortunately make some bundles bigger. No doubt, we
can also create examples where it will make them smaller ...
The bundle size for 4.0 (hg bundle --base null -r 4.0 x.hg) happens to go from
22803824 to 22806817 bytes - an 0.01% increase.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Tue, 08 Nov 2016 18:37:33 +0100 |
parents | 5c4e2636c1a9 |
children | 3633403888ae |
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 @@ -143,7 +143,7 @@ struct pos *pos, int a1, int a2, int b1, int b2, int *omi, int *omj) { - int mi = a1, mj = b1, mk = 0, i, j, k, half; + int mi = a1, mj = b1, mk = 0, i, j, k, half, bhalf; /* window our search on large regions to better bound worst-case performance. by choosing a window at the end, we @@ -152,6 +152,7 @@ a1 = a2 - 30000; half = (a1 + a2 - 1) / 2; + bhalf = (b1 + b2 - 1) / 2; for (i = a1; i < a2; i++) { /* skip all lines in b after the current block */ @@ -187,8 +188,8 @@ /* same match but closer to half */ mi = i; mj = j; - } else if (i == mi) { - /* same i but earlier j */ + } else if (i == mi && mj > bhalf) { + /* same i but best earlier j */ mj = j; } }