On Thu, 17 Nov 2016 18:16:40 +0100, Mads Kiilerich wrote: > # HG changeset patch > # User Mads Kiilerich <mad...@unity3d.com> > # Date 1479322051 -3600 > # Wed Nov 16 19:47:31 2016 +0100 > # Node ID 851a14d5b80639efe61bd01ad215479c99106b40 > # Parent 7f39bccc1c96bffc83f3c6e774da57ecd38982a7 > bdiff: early pruning of common suffix before doing expensive computations > > Similar to the previous change, but trimming trailing lines. > > On mozilla-unified: > perfbdiff -m 3041e4d59df2 > ! wall 0.024618 comb 0.020000 user 0.020000 sys 0.000000 (best of 116) to > ! wall 0.008259 comb 0.010000 user 0.010000 sys 0.000000 (best of 356) to > perfbdiff 0e9928989e9c --alldata --count 10 > ! wall 0.579235 comb 0.580000 user 0.580000 sys 0.000000 (best of 18) > ! wall 0.469869 comb 0.460000 user 0.460000 sys 0.000000 (best of 22) > > diff --git a/mercurial/bdiff_module.c b/mercurial/bdiff_module.c > --- a/mercurial/bdiff_module.c > +++ b/mercurial/bdiff_module.c > @@ -66,7 +66,7 @@ static PyObject *bdiff(PyObject *self, P > struct bdiff_line *al, *bl; > struct bdiff_hunk l, *h; > int an, bn, count; > - Py_ssize_t len = 0, la, lb, li = 0, lcommon = 0, lmax; > + Py_ssize_t len = 0, la, lb, li = 0, lcommon = 0, lcommonend = 0, lmax; > PyThreadState *_save; > > l.next = NULL; > @@ -88,9 +88,16 @@ static PyObject *bdiff(PyObject *self, P > if (*ia == '\n') > lcommon = li + 1; > /* we can almost add: if (li == lmax) lcommon = li; */ > + lmax -= lcommon; > + for (li = 0, ia = sa + la - 1, ib = sb + lb - 1; > + li <= lmax && *ia == *ib; > + ++li, --ia, --ib) > + if (*ia == '\n') > + lcommonend = li;
Perhaps this could read one byte before the sa and sb. For bdiff('', ''), li == lmax == 0 but ia == sa[-1]. _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel