Replace separate attrib key, value calls with single pair call

pull/5288/head
Richard Hansen 2021-11-18 20:06:56 -05:00
parent 6cf2055199
commit 1f227200da
3 changed files with 13 additions and 36 deletions

View File

@ -364,9 +364,6 @@ PadDiff.prototype._createDeletionChangeset = function (cs, startAText, apool) {
}; };
}; };
const attribKeys = [];
const attribValues = [];
// iterate over all operators of this changeset // iterate over all operators of this changeset
while (csIter.hasNext()) { while (csIter.hasNext()) {
const csOp = csIter.next(); const csOp = csIter.next();
@ -381,28 +378,17 @@ PadDiff.prototype._createDeletionChangeset = function (cs, startAText, apool) {
if (csOp.attribs && textBank !== '*') { if (csOp.attribs && textBank !== '*') {
const deletedAttrib = apool.putAttrib(['removed', true]); const deletedAttrib = apool.putAttrib(['removed', true]);
let authorAttrib = apool.putAttrib(['author', '']); let authorAttrib = apool.putAttrib(['author', '']);
const attribs = [];
attribKeys.length = 0;
attribValues.length = 0;
Changeset.eachAttribNumber(csOp.attribs, (n) => { Changeset.eachAttribNumber(csOp.attribs, (n) => {
attribKeys.push(apool.getAttribKey(n)); const attrib = apool.getAttrib(n);
attribValues.push(apool.getAttribValue(n)); attribs.push(attrib);
if (attrib[0] === 'author') authorAttrib = n;
if (apool.getAttribKey(n) === 'author') {
authorAttrib = n;
}
}); });
const undoBackToAttribs = cachedStrFunc((oldAttribsStr) => {
const undoBackToAttribs = cachedStrFunc((attribs) => {
const backAttribs = []; const backAttribs = [];
for (let i = 0; i < attribKeys.length; i++) { for (const [key, value] of attribs) {
const appliedKey = attribKeys[i]; const oldValue = Changeset.attribsAttributeValue(oldAttribsStr, key, apool);
const appliedValue = attribValues[i]; if (oldValue !== value) backAttribs.push([key, oldValue])
const oldValue = Changeset.attribsAttributeValue(attribs, appliedKey, apool);
if (appliedValue !== oldValue) {
backAttribs.push([appliedKey, oldValue]);
}
} }
return Changeset.makeAttribsString('=', backAttribs, apool); return Changeset.makeAttribsString('=', backAttribs, apool);

View File

@ -166,9 +166,7 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({
const op = opIter.next(); const op = opIter.next();
if (!op.attribs) return []; if (!op.attribs) return [];
const attributes = []; const attributes = [];
Changeset.eachAttribNumber(op.attribs, (n) => { Changeset.eachAttribNumber(op.attribs, (n) => attributes.push(this.rep.apool.getAttrib(n)));
attributes.push([this.rep.apool.getAttribKey(n), this.rep.apool.getAttribValue(n)]);
});
return attributes; return attributes;
}, },
@ -277,12 +275,8 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({
currentPointer += currentOperation.chars; currentPointer += currentOperation.chars;
if (currentPointer <= column) continue; if (currentPointer <= column) continue;
const attributes = []; const attributes = [];
Changeset.eachAttribNumber(currentOperation.attribs, (n) => { Changeset.eachAttribNumber(
attributes.push([ currentOperation.attribs, (n) => attributes.push(this.rep.apool.getAttrib(n)));
this.rep.apool.getAttribKey(n),
this.rep.apool.getAttribValue(n),
]);
});
return attributes; return attributes;
} }
return []; return [];

View File

@ -75,11 +75,8 @@ linestylefilter.getLineStyleFilter = (lineLength, aline, textAndClassFunc, apool
// For each attribute number // For each attribute number
Changeset.eachAttribNumber(attribs, (n) => { Changeset.eachAttribNumber(attribs, (n) => {
// Give us this attributes key const [key, value] = apool.getAttrib(n);
const key = apool.getAttribKey(n); if (!key || !value) return;
if (!key) return;
const value = apool.getAttribValue(n);
if (!value) return;
if (!isLineAttribMarker && AttributeManager.lineAttributes.indexOf(key) >= 0) { if (!isLineAttribMarker && AttributeManager.lineAttributes.indexOf(key) >= 0) {
isLineAttribMarker = true; isLineAttribMarker = true;
} }