diff --git a/README.md b/README.md index 242f992..f59ca61 100644 --- a/README.md +++ b/README.md @@ -196,6 +196,7 @@ The HTML output accepts a Javascript object with configuration. Possible options - `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` + - `maxLineSizeInBlockForComparison`: maximum number os characters of the bigger line in a block to apply comparison, default is `200` - `maxLineLengthHighlight`: only perform diff changes highlight if lines are smaller than this, default is `10000` - `templates`: object with previously compiled templates to replace parts of the html - `rawTemplates`: object with raw not compiled templates to replace parts of the html diff --git a/src/diff2html.js b/src/diff2html.js index 2da3271..8ef8339 100644 --- a/src/diff2html.js +++ b/src/diff2html.js @@ -19,6 +19,7 @@ matching: 'none', matchWordsThreshold: 0.25, matchingMaxComparisons: 2500, + maxLineSizeInBlockForComparison: 200, maxLineLengthHighlight: 10000, renderNothingWhenEmpty: false }; diff --git a/src/line-by-line-printer.js b/src/line-by-line-printer.js index 8b41cc5..33722b6 100644 --- a/src/line-by-line-printer.js +++ b/src/line-by-line-printer.js @@ -94,9 +94,17 @@ var deleteType; var comparisons = oldLines.length * newLines.length; - var maxComparisons = that.config.matchingMaxComparisons || 2500; - var doMatching = comparisons < maxComparisons && (that.config.matching === 'lines' || - that.config.matching === 'words'); + + var maxLineSizeInBlock = Math.max.apply(null, + [0].concat((oldLines.concat(newLines)).map( + function(elem) { + return elem.content.length; + } + ))); + + var doMatching = comparisons < that.config.matchingMaxComparisons && + maxLineSizeInBlock < that.config.maxLineSizeInBlockForComparison && + (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 26067be..6a739e5 100644 --- a/src/side-by-side-printer.js +++ b/src/side-by-side-printer.js @@ -96,9 +96,14 @@ var deleteType; var comparisons = oldLines.length * newLines.length; - var maxComparisons = that.config.matchingMaxComparisons || 2500; - var doMatching = comparisons < maxComparisons && (that.config.matching === 'lines' || - that.config.matching === 'words'); + + var maxLineSizeInBlock = Math.max.apply(null, (oldLines.concat(newLines)).map(function(elem) { + return elem.length; + })); + + var doMatching = comparisons < that.config.matchingMaxComparisons && + maxLineSizeInBlock < that.config.maxLineSizeInBlockForComparison && + (that.config.matching === 'lines' || that.config.matching === 'words'); if (doMatching) { matches = matcher(oldLines, newLines); diff --git a/test/line-by-line-tests.js b/test/line-by-line-tests.js index 529a71d..054b4d5 100644 --- a/test/line-by-line-tests.js +++ b/test/line-by-line-tests.js @@ -372,23 +372,23 @@ describe('LineByLinePrinter', function() { '