()
| 5865 | |
| 5866 | |
| 5867 | function execEditLength() { |
| 5868 | for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) { |
| 5869 | var basePath = |
| 5870 | /*istanbul ignore start*/ |
| 5871 | void 0 |
| 5872 | /*istanbul ignore end*/ |
| 5873 | ; |
| 5874 | |
| 5875 | var addPath = bestPath[diagonalPath - 1], |
| 5876 | removePath = bestPath[diagonalPath + 1], |
| 5877 | _oldPos = (removePath ? removePath.newPos : 0) - diagonalPath; |
| 5878 | |
| 5879 | if (addPath) { |
| 5880 | // No one else is going to attempt to use this value, clear it |
| 5881 | bestPath[diagonalPath - 1] = undefined; |
| 5882 | } |
| 5883 | |
| 5884 | var canAdd = addPath && addPath.newPos + 1 < newLen, |
| 5885 | canRemove = removePath && 0 <= _oldPos && _oldPos < oldLen; |
| 5886 | |
| 5887 | if (!canAdd && !canRemove) { |
| 5888 | // If this path is a terminal then prune |
| 5889 | bestPath[diagonalPath] = undefined; |
| 5890 | continue; |
| 5891 | } // Select the diagonal that we want to branch from. We select the prior |
| 5892 | // path whose position in the new string is the farthest from the origin |
| 5893 | // and does not pass the bounds of the diff graph |
| 5894 | |
| 5895 | |
| 5896 | if (!canAdd || canRemove && addPath.newPos < removePath.newPos) { |
| 5897 | basePath = clonePath(removePath); |
| 5898 | self.pushComponent(basePath.components, undefined, true); |
| 5899 | } else { |
| 5900 | basePath = addPath; // No need to clone, we've pulled it from the list |
| 5901 | |
| 5902 | basePath.newPos++; |
| 5903 | self.pushComponent(basePath.components, true, undefined); |
| 5904 | } |
| 5905 | |
| 5906 | _oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath); // If we have hit the end of both strings, then we are done |
| 5907 | |
| 5908 | if (basePath.newPos + 1 >= newLen && _oldPos + 1 >= oldLen) { |
| 5909 | return done(buildValues(self, basePath.components, newString, oldString, self.useLongestToken)); |
| 5910 | } else { |
| 5911 | // Otherwise track this path as a potential candidate and continue. |
| 5912 | bestPath[diagonalPath] = basePath; |
| 5913 | } |
| 5914 | } |
| 5915 | |
| 5916 | editLength++; |
| 5917 | } // Performs the length of edit iteration. Is a bit fugly as this has to support the |
| 5918 | // sync and async mode which is never fun. Loops over execEditLength until a value |
| 5919 | // is produced. |
| 5920 |
no test coverage detected