Skip to content

Commit 1f22720

Browse files
committed
Replace separate attrib key, value calls with single pair call
1 parent 6cf2055 commit 1f22720

File tree

3 files changed

+13
-36
lines changed

3 files changed

+13
-36
lines changed

src/node/utils/padDiff.js

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,6 @@ PadDiff.prototype._createDeletionChangeset = function (cs, startAText, apool) {
364364
};
365365
};
366366

367-
const attribKeys = [];
368-
const attribValues = [];
369-
370367
// iterate over all operators of this changeset
371368
while (csIter.hasNext()) {
372369
const csOp = csIter.next();
@@ -381,28 +378,17 @@ PadDiff.prototype._createDeletionChangeset = function (cs, startAText, apool) {
381378
if (csOp.attribs && textBank !== '*') {
382379
const deletedAttrib = apool.putAttrib(['removed', true]);
383380
let authorAttrib = apool.putAttrib(['author', '']);
384-
385-
attribKeys.length = 0;
386-
attribValues.length = 0;
381+
const attribs = [];
387382
Changeset.eachAttribNumber(csOp.attribs, (n) => {
388-
attribKeys.push(apool.getAttribKey(n));
389-
attribValues.push(apool.getAttribValue(n));
390-
391-
if (apool.getAttribKey(n) === 'author') {
392-
authorAttrib = n;
393-
}
383+
const attrib = apool.getAttrib(n);
384+
attribs.push(attrib);
385+
if (attrib[0] === 'author') authorAttrib = n;
394386
});
395-
396-
const undoBackToAttribs = cachedStrFunc((attribs) => {
387+
const undoBackToAttribs = cachedStrFunc((oldAttribsStr) => {
397388
const backAttribs = [];
398-
for (let i = 0; i < attribKeys.length; i++) {
399-
const appliedKey = attribKeys[i];
400-
const appliedValue = attribValues[i];
401-
const oldValue = Changeset.attribsAttributeValue(attribs, appliedKey, apool);
402-
403-
if (appliedValue !== oldValue) {
404-
backAttribs.push([appliedKey, oldValue]);
405-
}
389+
for (const [key, value] of attribs) {
390+
const oldValue = Changeset.attribsAttributeValue(oldAttribsStr, key, apool);
391+
if (oldValue !== value) backAttribs.push([key, oldValue])
406392
}
407393

408394
return Changeset.makeAttribsString('=', backAttribs, apool);

src/static/js/AttributeManager.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,7 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({
166166
const op = opIter.next();
167167
if (!op.attribs) return [];
168168
const attributes = [];
169-
Changeset.eachAttribNumber(op.attribs, (n) => {
170-
attributes.push([this.rep.apool.getAttribKey(n), this.rep.apool.getAttribValue(n)]);
171-
});
169+
Changeset.eachAttribNumber(op.attribs, (n) => attributes.push(this.rep.apool.getAttrib(n)));
172170
return attributes;
173171
},
174172

@@ -277,12 +275,8 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({
277275
currentPointer += currentOperation.chars;
278276
if (currentPointer <= column) continue;
279277
const attributes = [];
280-
Changeset.eachAttribNumber(currentOperation.attribs, (n) => {
281-
attributes.push([
282-
this.rep.apool.getAttribKey(n),
283-
this.rep.apool.getAttribValue(n),
284-
]);
285-
});
278+
Changeset.eachAttribNumber(
279+
currentOperation.attribs, (n) => attributes.push(this.rep.apool.getAttrib(n)));
286280
return attributes;
287281
}
288282
return [];

src/static/js/linestylefilter.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,8 @@ linestylefilter.getLineStyleFilter = (lineLength, aline, textAndClassFunc, apool
7575

7676
// For each attribute number
7777
Changeset.eachAttribNumber(attribs, (n) => {
78-
// Give us this attributes key
79-
const key = apool.getAttribKey(n);
80-
if (!key) return;
81-
const value = apool.getAttribValue(n);
82-
if (!value) return;
78+
const [key, value] = apool.getAttrib(n);
79+
if (!key || !value) return;
8380
if (!isLineAttribMarker && AttributeManager.lineAttributes.indexOf(key) >= 0) {
8481
isLineAttribMarker = true;
8582
}

0 commit comments

Comments
 (0)