Changeset: Use `clear()` to initialize

This avoids some duplicate code and it helps ensure that `clear()`
works properly.
rhansen-changeset
Richard Hansen 2021-11-23 02:59:06 -05:00
parent 8c01b66d40
commit 04ed432a01
1 changed files with 7 additions and 7 deletions

View File

@ -323,6 +323,11 @@ class OpAssembler {
class MergingOpAssembler {
constructor() {
this._assem = new OpAssembler();
this.clear();
}
clear() {
this._assem.clear();
this._bufOp = new Op();
// If we get, for example, insertions [xxx\n,yyy], those don't merge, but if we get
// [xxx\n,yyy,zzz\n], that merges to [xxx\nyyyzzz\n]. This variable stores the length of yyy and
@ -330,11 +335,6 @@ class MergingOpAssembler {
this._bufOpAdditionalCharsAfterNewline = 0;
}
clear() {
this._assem.clear();
clearOp(this._bufOp);
}
_flush(isEndDocument) {
if (!this._bufOp.opcode) return;
if (isEndDocument && this._bufOp.opcode === '=' && !this._bufOp.attribs) {
@ -431,8 +431,7 @@ class SmartOpAssembler {
this._plusAssem = new MergingOpAssembler();
this._keepAssem = new MergingOpAssembler();
this._assem = exports.stringAssembler();
this._lastOpcode = '';
this._lengthChange = 0;
this.clear();
}
clear() {
@ -440,6 +439,7 @@ class SmartOpAssembler {
this._plusAssem.clear();
this._keepAssem.clear();
this._assem.clear();
this._lastOpcode = '';
this._lengthChange = 0;
}