MCPcopy Create free account
hub / github.com/bigcode-project/jupytercoder / execEditLength

Function execEditLength

src/diff.js:62–108  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

60
61
62 function execEditLength() {
63 for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
64 var basePath = void 0;
65
66 var addPath = bestPath[diagonalPath - 1],
67 removePath = bestPath[diagonalPath + 1],
68 _oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
69
70 if (addPath) {
71 // No one else is going to attempt to use this value, clear it
72 bestPath[diagonalPath - 1] = undefined;
73 }
74
75 var canAdd = addPath && addPath.newPos + 1 < newLen,
76 canRemove = removePath && 0 <= _oldPos && _oldPos < oldLen;
77
78 if (!canAdd && !canRemove) {
79 // If this path is a terminal then prune
80 bestPath[diagonalPath] = undefined;
81 continue;
82 } // Select the diagonal that we want to branch from. We select the prior
83 // path whose position in the new string is the farthest from the origin
84 // and does not pass the bounds of the diff graph
85
86
87 if (!canAdd || canRemove && addPath.newPos < removePath.newPos) {
88 basePath = clonePath(removePath);
89 self.pushComponent(basePath.components, undefined, true);
90 } else {
91 basePath = addPath; // No need to clone, we've pulled it from the list
92
93 basePath.newPos++;
94 self.pushComponent(basePath.components, true, undefined);
95 }
96
97 _oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath); // If we have hit the end of both strings, then we are done
98
99 if (basePath.newPos + 1 >= newLen && _oldPos + 1 >= oldLen) {
100 return done(buildValues(self, basePath.components, newString, oldString, self.useLongestToken));
101 } else {
102 // Otherwise track this path as a potential candidate and continue.
103 bestPath[diagonalPath] = basePath;
104 }
105 }
106
107 editLength++;
108 } // Performs the length of edit iteration. Is a bit fugly as this has to support the
109 // sync and async mode which is never fun. Loops over execEditLength until a value
110 // is produced, or until the edit length exceeds options.maxEditLength (if given),
111 // in which case it will return undefined.

Callers 1

diff.jsFile · 0.85

Calls 3

clonePathFunction · 0.85
doneFunction · 0.85
buildValuesFunction · 0.85

Tested by

no test coverage detected