Changeset: Check .hasNext() before calling .next()

This commit is contained in:
Richard Hansen 2021-09-30 13:39:02 -04:00
parent 1955e7b263
commit 44d99733c6
3 changed files with 6 additions and 4 deletions

View file

@ -286,7 +286,7 @@ PadDiff.prototype._createDeletionChangeset = function (cs, startAText, apool) {
curLineOpIterLine = curLine;
let indexIntoLine = 0;
let done = false;
while (!done) {
while (!done && curLineOpIter.hasNext()) {
curLineNextOp = curLineOpIter.next();
if (indexIntoLine + curLineNextOp.chars >= curChar) {
curLineNextOp.chars -= (curChar - indexIntoLine);
@ -307,7 +307,7 @@ PadDiff.prototype._createDeletionChangeset = function (cs, startAText, apool) {
}
if (!curLineNextOp.chars) {
curLineNextOp = curLineOpIter.next();
curLineNextOp = curLineOpIter.hasNext() ? curLineOpIter.next() : Changeset.newOp();
}
const charsToUse = Math.min(numChars, curLineNextOp.chars);

View file

@ -2072,7 +2072,9 @@ exports.inverse = (cs, lines, alines, pool) => {
curLineNextOp.chars = 0;
curLineOpIter = exports.opIterator(alinesGet(curLine));
}
if (!curLineNextOp.chars) curLineNextOp = curLineOpIter.next();
if (!curLineNextOp.chars) {
curLineNextOp = curLineOpIter.hasNext() ? curLineOpIter.next() : exports.newOp();
}
const charsToUse = Math.min(numChars, curLineNextOp.chars);
func(charsToUse, curLineNextOp.attribs, charsToUse === curLineNextOp.chars &&
curLineNextOp.lines > 0);

View file

@ -108,7 +108,7 @@ linestylefilter.getLineStyleFilter = (lineLength, aline, textAndClassFunc, apool
let nextOp, nextOpClasses;
const goNextOp = () => {
nextOp = attributionIter.next();
nextOp = attributionIter.hasNext() ? attributionIter.next() : Changeset.newOp();
nextOpClasses = (nextOp.opcode && attribsToClasses(nextOp.attribs));
};
goNextOp();