Skip to content

Commit

Permalink
Move whitespace ignore out of equals method
Browse files Browse the repository at this point in the history
This adds overhead across the board and is only used in one place.
  • Loading branch information
kpdecker committed Aug 26, 2015
1 parent 4a0ba65 commit 542063c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 2 additions & 5 deletions src/diff/base.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export default function Diff(ignoreWhitespace) {
this.ignoreWhitespace = ignoreWhitespace;
}
export default function Diff() {}

Diff.prototype = {
diff(oldString, newString, callback) {
Expand Down Expand Up @@ -139,8 +137,7 @@ Diff.prototype = {
},

equals(left, right) {
let reWhitespace = /\S/;
return left === right || (this.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right));
return left === right;
},
removeEmpty(array) {
let ret = [];
Expand Down
8 changes: 7 additions & 1 deletion src/diff/word.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ import Diff from './base';
// Latin Extended Additional, 1E00–1EFF
const extendedWordChars = /^[a-zA-Z\u{C0}-\u{FF}\u{D8}-\u{F6}\u{F8}-\u{2C6}\u{2C8}-\u{2D7}\u{2DE}-\u{2FF}\u{1E00}-\u{1EFF}]+$/u;

export const wordDiff = new Diff(true);
const reWhitespace = /\S/;

export const wordDiff = new Diff();
wordDiff.equals = function(left, right) {
return left === right || (!reWhitespace.test(left) && !reWhitespace.test(right));
};

export const wordWithSpaceDiff = new Diff();
wordDiff.tokenize = wordWithSpaceDiff.tokenize = function(value) {
let tokens = value.split(/(\s+|\b)/);
Expand Down

0 comments on commit 542063c

Please sign in to comment.