From ffa06d52ce67f952e0c50ccc7371f50cfe27cfc6 Mon Sep 17 00:00:00 2001 From: Wei-Lun Li Date: Tue, 17 Nov 2026 01:24:33 +0900 Subject: [PATCH] perf: skip the emphasis closer scan for inline runs without a delimiter (#4195) --- src/Lexer.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Lexer.ts b/src/Lexer.ts index bdcd2396..5952b4a3 100644 --- a/src/Lexer.ts +++ b/src/Lexer.ts @@ -382,13 +382,19 @@ export class _Lexer { // The masked source is only read by emStrong and del, which need a *, _ or // ~ to start. Skip building it for a run without one, unless a custom // tokenizer or an emStrongMask hook may read it. - const maskedSrc = src.includes('*') || src.includes('_') || src.includes('~') + const hasDelimiter = src.includes('*') || src.includes('_') || src.includes('~'); + const maskedSrc = hasDelimiter || this.options.hooks?.emStrongMask || this.tokenizer.emStrong !== _Tokenizer.prototype.emStrong || this.tokenizer.del !== _Tokenizer.prototype.del ? this.#maskSrc(src) : src; + // Without a delimiter no opener can match, so nothing reads the closer scan. + if (!hasDelimiter) { + return this.#tokenizeInlines(src, maskedSrc, tokens); + } + // One scan of this maskedSrc for the last emphasis, strong, and // strikethrough closers, shared by every opener in the pass. Popped // when the pass ends so the source is not retained (#4099).