Revert removal of multi-match discard heuristic in 27af01

27af01d (xdiff/xprepare: improve O(n*m) performance in xdl_cleanup_records(), 2011-08-17) was supposed to be a performance boost only. However, it unexpectedly changed the behaviour of diff. Revert a part of 27af01d that removes logic that mark lines as "multi-match" (ie. dis[i] == 2). This was preventing the multi-match discard heuristic (performed in xdl_cleanup_records() and xdl_clean_mmatch()) from executing. Reported-by: Alexander Pepper <pepper@inf.fu-berlin.de> Signed-off-by: René Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Tay Ray Chuan <rctay89@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Sep 25, 2011 at 21:39 UTC c5aa90682f82fe0dabdc0280be93568d52efddfc
1 file changed +7 -3
xdiff/xprepare.c
+7 -3
@@ -398,7 +398,7 @@ static int xdl_clean_mmatch(char const *dis, long i, long s, long e) {
398 * might be potentially discarded if they happear in a run of discardable.
399 */
400 static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xdf2) {
401 - long i, nm, nreff;
401 + long i, nm, nreff, mlim;
402 xrecord_t **recs;
403 xdlclass_t *rcrec;
404 char *dis, *dis1, *dis2;
@@ -411,16 +411,20 @@ static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xd
411 dis1 = dis;
412 dis2 = dis1 + xdf1->nrec + 1;
413
414 + if ((mlim = xdl_bogosqrt(xdf1->nrec)) > XDL_MAX_EQLIMIT)
415 + mlim = XDL_MAX_EQLIMIT;
416 for (i = xdf1->dstart, recs = &xdf1->recs[xdf1->dstart]; i <= xdf1->dend; i++, recs++) {
417 rcrec = cf->rcrecs[(*recs)->ha];
418 nm = rcrec ? rcrec->len2 : 0;
417 - dis1[i] = (nm == 0) ? 0: 1;
419 + dis1[i] = (nm == 0) ? 0: (nm >= mlim) ? 2: 1;
420 }
421
422 + if ((mlim = xdl_bogosqrt(xdf2->nrec)) > XDL_MAX_EQLIMIT)
423 + mlim = XDL_MAX_EQLIMIT;
424 for (i = xdf2->dstart, recs = &xdf2->recs[xdf2->dstart]; i <= xdf2->dend; i++, recs++) {
425 rcrec = cf->rcrecs[(*recs)->ha];
426 nm = rcrec ? rcrec->len1 : 0;
423 - dis2[i] = (nm == 0) ? 0: 1;
427 + dis2[i] = (nm == 0) ? 0: (nm >= mlim) ? 2: 1;
428 }
429
430 for (nreff = 0, i = xdf1->dstart, recs = &xdf1->recs[xdf1->dstart];