diff --git a/README.md b/README.md index 5575856..3de1132 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,7 @@ The HTML output accepts a Javascript object with configuration. Possible options - `showFiles`: show a file list before the diff: `true` or `false`, default is `false` - `matching`: matching level: `'lines'` for matching lines, `'words'` for matching lines and words or `'none'`, default is `none` - `matchWordsThreshold`: similarity threshold for word matching, default is 0.25 + - `matchingMaxComparisons`: perform at most this much comparisons for line matching a block of changes, default is `2500` ## Diff2HtmlUI Helper diff --git a/src/line-by-line-printer.js b/src/line-by-line-printer.js index 01059c4..88130ca 100644 --- a/src/line-by-line-printer.js +++ b/src/line-by-line-printer.js @@ -66,7 +66,10 @@ var insertType; var deleteType; - var doMatching = that.config.matching === 'lines' || that.config.matching === 'words'; + var comparisons = oldLines.length * newLines.length; + var maxComparisons = that.config.matchingMaxComparisons || 2500; + var doMatching = comparisons < maxComparisons && (that.config.matching === 'lines' || + that.config.matching === 'words'); if (doMatching) { matches = matcher(oldLines, newLines); diff --git a/src/side-by-side-printer.js b/src/side-by-side-printer.js index 6d4dbbe..fbf2360 100644 --- a/src/side-by-side-printer.js +++ b/src/side-by-side-printer.js @@ -105,7 +105,11 @@ var matches; var insertType; var deleteType; - var doMatching = that.config.matching === 'lines' || that.config.matching === 'words'; + + var comparisons = oldLines.length * newLines.length; + var maxComparisons = that.config.matchingMaxComparisons || 2500; + var doMatching = comparisons < maxComparisons && (that.config.matching === 'lines' || + that.config.matching === 'words'); if (doMatching) { matches = matcher(oldLines, newLines);