MCPcopy Create free account
hub / github.com/garris/BackstopJS / execEditLength

Function execEditLength

compare/output/diff.js:225–268  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

223
224 // Main worker method. checks all permutations of a given edit length for acceptance.
225 function execEditLength() {
226 for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
227 var basePath = /*istanbul ignore start*/void 0 /*istanbul ignore end*/;
228 var addPath = bestPath[diagonalPath - 1],
229 removePath = bestPath[diagonalPath + 1],
230 _oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
231 if (addPath) {
232 // No one else is going to attempt to use this value, clear it
233 bestPath[diagonalPath - 1] = undefined;
234 }
235
236 var canAdd = addPath && addPath.newPos + 1 < newLen,
237 canRemove = removePath && 0 <= _oldPos && _oldPos < oldLen;
238 if (!canAdd && !canRemove) {
239 // If this path is a terminal then prune
240 bestPath[diagonalPath] = undefined;
241 continue;
242 }
243
244 // Select the diagonal that we want to branch from. We select the prior
245 // path whose position in the new string is the farthest from the origin
246 // and does not pass the bounds of the diff graph
247 if (!canAdd || canRemove && addPath.newPos < removePath.newPos) {
248 basePath = clonePath(removePath);
249 self.pushComponent(basePath.components, undefined, true);
250 } else {
251 basePath = addPath; // No need to clone, we've pulled it from the list
252 basePath.newPos++;
253 self.pushComponent(basePath.components, true, undefined);
254 }
255
256 _oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath);
257
258 // If we have hit the end of both strings, then we are done
259 if (basePath.newPos + 1 >= newLen && _oldPos + 1 >= oldLen) {
260 return done(buildValues(self, basePath.components, newString, oldString, self.useLongestToken));
261 } else {
262 // Otherwise track this path as a potential candidate and continue.
263 bestPath[diagonalPath] = basePath;
264 }
265 }
266
267 editLength++;
268 }
269
270 // Performs the length of edit iteration. Is a bit fugly as this has to support the
271 // sync and async mode which is never fun. Loops over execEditLength until a value

Callers 1

diff.jsFile · 0.85

Calls 3

clonePathFunction · 0.85
doneFunction · 0.85
buildValuesFunction · 0.85

Tested by

no test coverage detected