Cap line matching comparisons

This commit is contained in:
Wolfgang Illmeyer 2016-04-14 13:01:25 +02:00
parent 3929ca28fc
commit ee494b88e5
3 changed files with 10 additions and 2 deletions

View file

@ -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

View file

@ -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);

View file

@ -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);