Skip to content

Commit 0d95036

Browse files
committed
Changeset: Turn stringAssembler() into a real class
1 parent 79f7412 commit 0d95036

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

src/static/js/Changeset.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -713,24 +713,21 @@ exports.stringIterator = (str) => {
713713

714714
/**
715715
* A custom made StringBuffer
716-
*
717-
* @typedef {object} StringAssembler
718-
* @property {Function} append -
719-
* @property {Function} toString -
720716
*/
717+
class StringAssembler {
718+
constructor() { this.clear(); }
719+
clear() { this._str = ''; }
720+
/**
721+
* @param {string} x -
722+
*/
723+
append(x) { this._str += String(x); }
724+
toString() { return this._str; }
725+
}
721726

722727
/**
723728
* @returns {StringAssembler}
724729
*/
725-
exports.stringAssembler = () => ({
726-
_str: '',
727-
clear() { this._str = ''; },
728-
/**
729-
* @param {string} x -
730-
*/
731-
append(x) { this._str += String(x); },
732-
toString() { return this._str; },
733-
});
730+
exports.stringAssembler = () => new StringAssembler();
734731

735732
/**
736733
* @typedef {object} StringArrayLike
@@ -1159,7 +1156,7 @@ exports.applyToText = (cs, str) => {
11591156
assert(str.length === unpacked.oldLen, `mismatched apply: ${str.length} / ${unpacked.oldLen}`);
11601157
const bankIter = exports.stringIterator(unpacked.charBank);
11611158
const strIter = exports.stringIterator(str);
1162-
const assem = exports.stringAssembler();
1159+
const assem = new StringAssembler();
11631160
for (const op of exports.deserializeOps(unpacked.ops)) {
11641161
switch (op.opcode) {
11651162
case '+':
@@ -1478,7 +1475,7 @@ exports.compose = (cs1, cs2, pool) => {
14781475
const len3 = unpacked2.newLen;
14791476
const bankIter1 = exports.stringIterator(unpacked1.charBank);
14801477
const bankIter2 = exports.stringIterator(unpacked2.charBank);
1481-
const bankAssem = exports.stringAssembler();
1478+
const bankAssem = new StringAssembler();
14821479

14831480
const newOps = applyZip(unpacked1.ops, unpacked2.ops, (op1, op2) => {
14841481
const op1code = op1.opcode;
@@ -1926,7 +1923,7 @@ class Builder {
19261923
constructor(oldLen) {
19271924
this._oldLen = oldLen;
19281925
this._ops = [];
1929-
this._charBank = exports.stringAssembler();
1926+
this._charBank = new StringAssembler();
19301927
}
19311928

19321929
/**
@@ -2187,7 +2184,7 @@ exports.inverse = (cs, lines, alines, pool) => {
21872184

21882185
const nextText = (numChars) => {
21892186
let len = 0;
2190-
const assem = exports.stringAssembler();
2187+
const assem = new StringAssembler();
21912188
const firstString = linesGet(curLine).substring(curChar);
21922189
len += firstString.length;
21932190
assem.append(firstString);
@@ -2413,7 +2410,7 @@ const followAttributes = (att1, att2, pool) => {
24132410
return '';
24142411
});
24152412
// we've only removed attributes, so they're already sorted
2416-
const buf = exports.stringAssembler();
2413+
const buf = new StringAssembler();
24172414
for (const att of atts) {
24182415
buf.append('*');
24192416
buf.append(exports.numToString(pool.putAttrib(att)));

0 commit comments

Comments
 (0)