From eb65910c1ba26733cf4cef4ef9157927b08826b8 Mon Sep 17 00:00:00 2001 From: Ismail Pelaseyed Date: Thu, 23 Apr 2026 15:35:06 +0200 Subject: [PATCH] perf: simplify CSI fast-path - drop intermediate handling and extra length checks Remove intermediate byte handling from the fast-path, bail to table lookup instead. Remove redundant per-step length checks by requiring i + 2 < length upfront and letting the for-loop guard the rest. --- src/common/parser/EscapeSequenceParser.ts | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/common/parser/EscapeSequenceParser.ts b/src/common/parser/EscapeSequenceParser.ts index 04f5e8862..99770b092 100644 --- a/src/common/parser/EscapeSequenceParser.ts +++ b/src/common/parser/EscapeSequenceParser.ts @@ -660,17 +660,16 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP // CSI fast-path: collapse ESC [ into a single entry, parse params+final in a tight loop if (code === 0x1b && this.currentState < ParserState.OSC_STRING - && i + 1 < length && data[i + 1] === 0x5b + && i + 2 < length && data[i + 1] === 0x5b ) { this._params.reset(); this._params.addParam(0); // ZDM this._collect = 0; let k = i + 2; - if (k >= length) { i = k - 1; this.currentState = ParserState.CSI_ENTRY; continue; } let ch = data[k]; if (ch >= 0x3c && ch <= 0x3f) { this._collect = ch; - if (++k >= length) { i = k - 1; this.currentState = ParserState.CSI_PARAM; continue; } + k++; } let csiDone = false; for (; k < length; k++) { @@ -702,13 +701,6 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP this.currentState = ParserState.GROUND; csiDone = true; break; - } else if (ch >= 0x20 && ch <= 0x2f) { - this._collect <<= 8; - this._collect |= ch; - i = k; - this.currentState = ParserState.CSI_INTERMEDIATE; - csiDone = true; - break; } else { break; }