Skip to content

Commit ac2abb4

Browse files
committed
Merge branch 'dl/xdiff'
* dl/xdiff: xdiff: give up scanning similar lines early
2 parents b2b80c1 + 9b28d55 commit ac2abb4

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

xdiff/xprepare.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@
2323
#include "xinclude.h"
2424

2525

26-
2726
#define XDL_KPDIS_RUN 4
2827
#define XDL_MAX_EQLIMIT 1024
29-
28+
#define XDL_SIMSCAN_WINDOW 100
3029

3130

3231
typedef struct s_xdlclass {
@@ -312,6 +311,18 @@ void xdl_free_env(xdfenv_t *xe) {
312311
static int xdl_clean_mmatch(char const *dis, long i, long s, long e) {
313312
long r, rdis0, rpdis0, rdis1, rpdis1;
314313

314+
/*
315+
* Limits the window the is examined during the similar-lines
316+
* scan. The loops below stops when dis[i - r] == 1 (line that
317+
* has no match), but there are corner cases where the loop
318+
* proceed all the way to the extremities by causing huge
319+
* performance penalties in case of big files.
320+
*/
321+
if (i - s > XDL_SIMSCAN_WINDOW)
322+
s = i - XDL_SIMSCAN_WINDOW;
323+
if (e - i > XDL_SIMSCAN_WINDOW)
324+
e = i + XDL_SIMSCAN_WINDOW;
325+
315326
/*
316327
* Scans the lines before 'i' to find a run of lines that either
317328
* have no match (dis[j] == 0) or have multiple matches (dis[j] > 1).

0 commit comments

Comments
 (0)