From 1f227200da1690e5bcb6389a5f83be8bc2556171 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Thu, 18 Nov 2021 20:06:56 -0500 Subject: [PATCH] Replace separate attrib key, value calls with single pair call --- src/node/utils/padDiff.js | 30 ++++++++---------------------- src/static/js/AttributeManager.js | 12 +++--------- src/static/js/linestylefilter.js | 7 ++----- 3 files changed, 13 insertions(+), 36 deletions(-) diff --git a/src/node/utils/padDiff.js b/src/node/utils/padDiff.js index 670e8d6a1..02fbdd99f 100644 --- a/src/node/utils/padDiff.js +++ b/src/node/utils/padDiff.js @@ -364,9 +364,6 @@ PadDiff.prototype._createDeletionChangeset = function (cs, startAText, apool) { }; }; - const attribKeys = []; - const attribValues = []; - // iterate over all operators of this changeset while (csIter.hasNext()) { const csOp = csIter.next(); @@ -381,28 +378,17 @@ PadDiff.prototype._createDeletionChangeset = function (cs, startAText, apool) { if (csOp.attribs && textBank !== '*') { const deletedAttrib = apool.putAttrib(['removed', true]); let authorAttrib = apool.putAttrib(['author', '']); - - attribKeys.length = 0; - attribValues.length = 0; + const attribs = []; Changeset.eachAttribNumber(csOp.attribs, (n) => { - attribKeys.push(apool.getAttribKey(n)); - attribValues.push(apool.getAttribValue(n)); - - if (apool.getAttribKey(n) === 'author') { - authorAttrib = n; - } + const attrib = apool.getAttrib(n); + attribs.push(attrib); + if (attrib[0] === 'author') authorAttrib = n; }); - - const undoBackToAttribs = cachedStrFunc((attribs) => { + const undoBackToAttribs = cachedStrFunc((oldAttribsStr) => { const backAttribs = []; - for (let i = 0; i < attribKeys.length; i++) { - const appliedKey = attribKeys[i]; - const appliedValue = attribValues[i]; - const oldValue = Changeset.attribsAttributeValue(attribs, appliedKey, apool); - - if (appliedValue !== oldValue) { - backAttribs.push([appliedKey, oldValue]); - } + for (const [key, value] of attribs) { + const oldValue = Changeset.attribsAttributeValue(oldAttribsStr, key, apool); + if (oldValue !== value) backAttribs.push([key, oldValue]) } return Changeset.makeAttribsString('=', backAttribs, apool); diff --git a/src/static/js/AttributeManager.js b/src/static/js/AttributeManager.js index d5b650bd5..760422427 100644 --- a/src/static/js/AttributeManager.js +++ b/src/static/js/AttributeManager.js @@ -166,9 +166,7 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({ const op = opIter.next(); if (!op.attribs) return []; const attributes = []; - Changeset.eachAttribNumber(op.attribs, (n) => { - attributes.push([this.rep.apool.getAttribKey(n), this.rep.apool.getAttribValue(n)]); - }); + Changeset.eachAttribNumber(op.attribs, (n) => attributes.push(this.rep.apool.getAttrib(n))); return attributes; }, @@ -277,12 +275,8 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({ currentPointer += currentOperation.chars; if (currentPointer <= column) continue; const attributes = []; - Changeset.eachAttribNumber(currentOperation.attribs, (n) => { - attributes.push([ - this.rep.apool.getAttribKey(n), - this.rep.apool.getAttribValue(n), - ]); - }); + Changeset.eachAttribNumber( + currentOperation.attribs, (n) => attributes.push(this.rep.apool.getAttrib(n))); return attributes; } return []; diff --git a/src/static/js/linestylefilter.js b/src/static/js/linestylefilter.js index c0a81e9da..0821889c7 100644 --- a/src/static/js/linestylefilter.js +++ b/src/static/js/linestylefilter.js @@ -75,11 +75,8 @@ linestylefilter.getLineStyleFilter = (lineLength, aline, textAndClassFunc, apool // For each attribute number Changeset.eachAttribNumber(attribs, (n) => { - // Give us this attributes key - const key = apool.getAttribKey(n); - if (!key) return; - const value = apool.getAttribValue(n); - if (!value) return; + const [key, value] = apool.getAttrib(n); + if (!key || !value) return; if (!isLineAttribMarker && AttributeManager.lineAttributes.indexOf(key) >= 0) { isLineAttribMarker = true; }