Skip to content

Commit 3e4af64

Browse files
committed
Changeset: Use for...of iteration to improve readability
1 parent 5aaf59d commit 3e4af64

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

src/static/js/Changeset.js

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,9 +1146,9 @@ exports.composeAttributes = (att1, att2, resultIsMutation, pool) => {
11461146
});
11471147
atts.sort();
11481148
const buf = exports.stringAssembler();
1149-
for (let i = 0; i < atts.length; i++) {
1149+
for (const att of atts) {
11501150
buf.append('*');
1151-
buf.append(exports.numToString(pool.putAttrib(atts[i])));
1151+
buf.append(exports.numToString(pool.putAttrib(att)));
11521152
}
11531153
return buf.toString();
11541154
};
@@ -1306,8 +1306,7 @@ exports.mutateAttributionLines = (cs, lines, pool) => {
13061306
*/
13071307
exports.joinAttributionLines = (theAlines) => {
13081308
const assem = exports.mergingOpAssembler();
1309-
for (let i = 0; i < theAlines.length; i++) {
1310-
const aline = theAlines[i];
1309+
for (const aline of theAlines) {
13111310
const iter = exports.opIterator(aline);
13121311
while (iter.hasNext()) {
13131312
assem.append(iter.next());
@@ -1507,10 +1506,8 @@ const toSplices = (cs) => {
15071506
exports.characterRangeFollow = (cs, startChar, endChar, insertionsAfter) => {
15081507
let newStartChar = startChar;
15091508
let newEndChar = endChar;
1510-
const splices = toSplices(cs);
15111509
let lengthChangeSoFar = 0;
1512-
for (let i = 0; i < splices.length; i++) {
1513-
const splice = splices[i];
1510+
for (const splice of toSplices(cs)) {
15141511
const spliceStart = splice[0] + lengthChangeSoFar;
15151512
const spliceEnd = splice[1] + lengthChangeSoFar;
15161513
const newTextLength = splice[2].length;
@@ -1906,8 +1903,7 @@ exports.makeAttribsString = (opcode, attribs, pool) => {
19061903
attribs.sort();
19071904
}
19081905
const result = [];
1909-
for (let i = 0; i < attribs.length; i++) {
1910-
const pair = attribs[i];
1906+
for (const pair of attribs) {
19111907
if (opcode === '=' || (opcode === '+' && pair[1])) {
19121908
result.push(`*${exports.numToString(pool.putAttrib(pair))}`);
19131909
}
@@ -2072,23 +2068,15 @@ exports.inverse = (cs, lines, alines, pool) => {
20722068
};
20732069
};
20742070

2075-
const attribKeys = [];
2076-
const attribValues = [];
20772071
while (csIter.hasNext()) {
20782072
const csOp = csIter.next();
20792073
if (csOp.opcode === '=') {
20802074
if (csOp.attribs) {
2081-
attribKeys.length = 0;
2082-
attribValues.length = 0;
2083-
exports.eachAttribNumber(csOp.attribs, (n) => {
2084-
attribKeys.push(pool.getAttribKey(n));
2085-
attribValues.push(pool.getAttribValue(n));
2086-
});
2075+
const csAttribs = [];
2076+
exports.eachAttribNumber(csOp.attribs, (n) => csAttribs.push(pool.getAttrib(n)));
20872077
const undoBackToAttribs = cachedStrFunc((attribs) => {
20882078
const backAttribs = [];
2089-
for (let i = 0; i < attribKeys.length; i++) {
2090-
const appliedKey = attribKeys[i];
2091-
const appliedValue = attribValues[i];
2079+
for (const [appliedKey, appliedValue] of csAttribs) {
20922080
const oldValue = exports.attribsAttributeValue(attribs, appliedKey, pool);
20932081
if (appliedValue !== oldValue) {
20942082
backAttribs.push([appliedKey, oldValue]);
@@ -2289,9 +2277,9 @@ const followAttributes = (att1, att2, pool) => {
22892277
});
22902278
// we've only removed attributes, so they're already sorted
22912279
const buf = exports.stringAssembler();
2292-
for (let i = 0; i < atts.length; i++) {
2280+
for (const att of atts) {
22932281
buf.append('*');
2294-
buf.append(exports.numToString(pool.putAttrib(atts[i])));
2282+
buf.append(exports.numToString(pool.putAttrib(att)));
22952283
}
22962284
return buf.toString();
22972285
};

0 commit comments

Comments
 (0)