Skip to content

Commit eaebe2a

Browse files
committed
refactor: add Params.resetZdm() to collapse reset+addParam(0) into single call
Replaces 10 separate reset()+addParam(0) pairs across the parser with a single resetZdm() method that inlines both operations, avoiding two calls to a foreign object per sequence reset.
1 parent 32553b4 commit eaebe2a

3 files changed

Lines changed: 23 additions & 18 deletions

File tree

src/common/parser/EscapeSequenceParser.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,7 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
462462
this._oscParser.reset();
463463
this._dcsParser.reset();
464464
this._apcParser.reset();
465-
this._params.reset();
466-
this._params.addParam(0); // ZDM
465+
this._params.resetZdm();
467466
this._collect = 0;
468467
this.precedingJoinState = 0;
469468
// abort pending continuation from async handler
@@ -612,8 +611,7 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
612611
return handlerResult;
613612
}
614613
if (code === 0x1b) this._parseStack.transition |= ParserState.ESCAPE;
615-
this._params.reset();
616-
this._params.addParam(0); // ZDM
614+
this._params.resetZdm();
617615
this._collect = 0;
618616
break;
619617
case ParserStackType.OSC:
@@ -623,8 +621,7 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
623621
return handlerResult;
624622
}
625623
if (code === 0x1b) this._parseStack.transition |= ParserState.ESCAPE;
626-
this._params.reset();
627-
this._params.addParam(0); // ZDM
624+
this._params.resetZdm();
628625
this._collect = 0;
629626
break;
630627
case ParserStackType.APC:
@@ -634,8 +631,7 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
634631
return handlerResult;
635632
}
636633
if (code === 0x1b) this._parseStack.transition |= ParserState.ESCAPE;
637-
this._params.reset();
638-
this._params.addParam(0); // ZDM
634+
this._params.resetZdm();
639635
this._collect = 0;
640636
break;
641637
}
@@ -666,8 +662,7 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
666662
&& this.currentState < ParserState.OSC_STRING
667663
&& i + 2 < length && data[i + 1] === 0x5b
668664
) {
669-
this._params.reset();
670-
this._params.addParam(0); // ZDM
665+
this._params.resetZdm();
671666
this._collect = 0;
672667
let k = i + 2;
673668
let ch = data[k];
@@ -817,8 +812,7 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
817812
this.precedingJoinState = 0;
818813
break;
819814
case ParserAction.CLEAR:
820-
this._params.reset();
821-
this._params.addParam(0); // ZDM
815+
this._params.resetZdm();
822816
this._collect = 0;
823817
break;
824818
case ParserAction.DCS_HOOK:
@@ -842,8 +836,7 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
842836
return handlerResult;
843837
}
844838
if (code === 0x1b) transition |= ParserState.ESCAPE;
845-
this._params.reset();
846-
this._params.addParam(0); // ZDM
839+
this._params.resetZdm();
847840
this._collect = 0;
848841
this.precedingJoinState = 0;
849842
break;
@@ -867,8 +860,7 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
867860
return handlerResult;
868861
}
869862
if (code === 0x1b) transition |= ParserState.ESCAPE;
870-
this._params.reset();
871-
this._params.addParam(0); // ZDM
863+
this._params.resetZdm();
872864
this._collect = 0;
873865
this.precedingJoinState = 0;
874866
break;
@@ -892,8 +884,7 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
892884
return handlerResult;
893885
}
894886
if (code === 0x1b) transition |= ParserState.ESCAPE;
895-
this._params.reset();
896-
this._params.addParam(0); // ZDM
887+
this._params.resetZdm();
897888
this._collect = 0;
898889
this.precedingJoinState = 0;
899890
break;

src/common/parser/Params.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,19 @@ export class Params implements IParams {
129129
this._digitIsSub = false;
130130
}
131131

132+
/**
133+
* Reset and add 0 as first param (ZDM).
134+
*/
135+
public resetZdm(): void {
136+
this.length = 1;
137+
this._subParamsLength = 0;
138+
this._rejectDigits = false;
139+
this._rejectSubDigits = false;
140+
this._digitIsSub = false;
141+
this._subParamsIdx[0] = 0;
142+
this.params[0] = 0;
143+
}
144+
132145
/**
133146
* Add a parameter value.
134147
* `Params` only stores up to `maxLength` parameters, any later

src/common/parser/Types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export interface IParams {
3232
clone(): IParams;
3333
toArray(): ParamsArray;
3434
reset(): void;
35+
resetZdm(): void;
3536
addParam(value: number): void;
3637
addSubParam(value: number): void;
3738
hasSubParams(idx: number): boolean;

0 commit comments

Comments
 (0)