Patchwork D2629: xdiff: do not rely on hashtable in xdl_trim_ends

login
register
mail settings
Submitter phabricator
Date March 4, 2018, 2:51 a.m.
Message ID <differential-rev-PHID-DREV-tnorsae4lmzvhjwq4pl5-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/28893/
State Superseded
Headers show

Comments

phabricator - March 4, 2018, 2:51 a.m.
quark created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Upcoming changes will narrow down the hashtable content to not include
  trimmed lines. So let's just compare line contents in `xdl_trim_ends`.
  It's still cheaper than calculating unique hash values for all lines.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2629

AFFECTED FILES
  mercurial/thirdparty/xdiff/xprepare.c

CHANGE DETAILS




To: quark, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/thirdparty/xdiff/xprepare.c b/mercurial/thirdparty/xdiff/xprepare.c
--- a/mercurial/thirdparty/xdiff/xprepare.c
+++ b/mercurial/thirdparty/xdiff/xprepare.c
@@ -441,17 +441,27 @@ 
 	recs1 = xdf1->recs;
 	recs2 = xdf2->recs;
 	for (i = 0, lim = XDL_MIN(xdf1->nrec, xdf2->nrec); i < lim;
-	     i++, recs1++, recs2++)
-		if ((*recs1)->ha != (*recs2)->ha)
+	     i++, recs1++, recs2++) {
+		/* rec->ha is not processed by xdl_prepare_hashtable, so
+		 * they are not unique - do a content match here */
+		if ((*recs1)->size != (*recs2)->size)
 			break;
+		if (memcmp((*recs1)->ptr, (*recs2)->ptr, (*recs1)->size) != 0)
+			break;
+	}
 
 	xdf1->dstart = xdf2->dstart = i;
 
 	recs1 = xdf1->recs + xdf1->nrec - 1;
 	recs2 = xdf2->recs + xdf2->nrec - 1;
-	for (lim -= i, i = 0; i < lim; i++, recs1--, recs2--)
-		if ((*recs1)->ha != (*recs2)->ha)
+	for (lim -= i, i = 0; i < lim; i++, recs1--, recs2--) {
+		/* rec->ha is not processed by xdl_prepare_hashtable, so
+		 * they are not unique - do a content match here */
+		if ((*recs1)->size != (*recs2)->size)
 			break;
+		if (memcmp((*recs1)->ptr, (*recs2)->ptr, (*recs1)->size) != 0)
+			break;
+	}
 
 	xdf1->dend = xdf1->nrec - i - 1;
 	xdf2->dend = xdf2->nrec - i - 1;