Skip to content

Commit 49f4abf

Browse files
committed
Changeset: Use for...of iteration to improve readability
1 parent 1eb5ec2 commit 49f4abf

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
@@ -1144,9 +1144,9 @@ exports.composeAttributes = (att1, att2, resultIsMutation, pool) => {
11441144
});
11451145
atts.sort();
11461146
const buf = exports.stringAssembler();
1147-
for (let i = 0; i < atts.length; i++) {
1147+
for (const att of atts) {
11481148
buf.append('*');
1149-
buf.append(exports.numToString(pool.putAttrib(atts[i])));
1149+
buf.append(exports.numToString(pool.putAttrib(att)));
11501150
}
11511151
return buf.toString();
11521152
};
@@ -1304,8 +1304,7 @@ exports.mutateAttributionLines = (cs, lines, pool) => {
13041304
*/
13051305
exports.joinAttributionLines = (theAlines) => {
13061306
const assem = exports.mergingOpAssembler();
1307-
for (let i = 0; i < theAlines.length; i++) {
1308-
const aline = theAlines[i];
1307+
for (const aline of theAlines) {
13091308
const iter = exports.opIterator(aline);
13101309
while (iter.hasNext()) {
13111310
assem.append(iter.next());
@@ -1505,10 +1504,8 @@ const toSplices = (cs) => {
15051504
exports.characterRangeFollow = (cs, startChar, endChar, insertionsAfter) => {
15061505
let newStartChar = startChar;
15071506
let newEndChar = endChar;
1508-
const splices = toSplices(cs);
15091507
let lengthChangeSoFar = 0;
1510-
for (let i = 0; i < splices.length; i++) {
1511-
const splice = splices[i];
1508+
for (const splice of toSplices(cs)) {
15121509
const spliceStart = splice[0] + lengthChangeSoFar;
15131510
const spliceEnd = splice[1] + lengthChangeSoFar;
15141511
const newTextLength = splice[2].length;
@@ -1904,8 +1901,7 @@ exports.makeAttribsString = (opcode, attribs, pool) => {
19041901
attribs.sort();
19051902
}
19061903
const result = [];
1907-
for (let i = 0; i < attribs.length; i++) {
1908-
const pair = attribs[i];
1904+
for (const pair of attribs) {
19091905
if (opcode === '=' || (opcode === '+' && pair[1])) {
19101906
result.push(`*${exports.numToString(pool.putAttrib(pair))}`);
19111907
}
@@ -2070,23 +2066,15 @@ exports.inverse = (cs, lines, alines, pool) => {
20702066
};
20712067
};
20722068

2073-
const attribKeys = [];
2074-
const attribValues = [];
20752069
while (csIter.hasNext()) {
20762070
const csOp = csIter.next();
20772071
if (csOp.opcode === '=') {
20782072
if (csOp.attribs) {
2079-
attribKeys.length = 0;
2080-
attribValues.length = 0;
2081-
exports.eachAttribNumber(csOp.attribs, (n) => {
2082-
attribKeys.push(pool.getAttribKey(n));
2083-
attribValues.push(pool.getAttribValue(n));
2084-
});
2073+
const csAttribs = [];
2074+
exports.eachAttribNumber(csOp.attribs, (n) => csAttribs.push(pool.getAttrib(n)));
20852075
const undoBackToAttribs = cachedStrFunc((attribs) => {
20862076
const backAttribs = [];
2087-
for (let i = 0; i < attribKeys.length; i++) {
2088-
const appliedKey = attribKeys[i];
2089-
const appliedValue = attribValues[i];
2077+
for (const [appliedKey, appliedValue] of csAttribs) {
20902078
const oldValue = exports.attribsAttributeValue(attribs, appliedKey, pool);
20912079
if (appliedValue !== oldValue) {
20922080
backAttribs.push([appliedKey, oldValue]);
@@ -2287,9 +2275,9 @@ const followAttributes = (att1, att2, pool) => {
22872275
});
22882276
// we've only removed attributes, so they're already sorted
22892277
const buf = exports.stringAssembler();
2290-
for (let i = 0; i < atts.length; i++) {
2278+
for (const att of atts) {
22912279
buf.append('*');
2292-
buf.append(exports.numToString(pool.putAttrib(atts[i])));
2280+
buf.append(exports.numToString(pool.putAttrib(att)));
22932281
}
22942282
return buf.toString();
22952283
};

0 commit comments

Comments
 (0)