perf: skip the emphasis closer scan for inline runs without a delimiter (#4195)

This commit is contained in:
Wei-Lun Li
2026-11-16 09:24:33 -07:00
committed by GitHub
parent 95ccf6c186
commit ffa06d52ce
+7 -1
View File
@@ -382,13 +382,19 @@ export class _Lexer<ParserOutput = string, RendererOutput = string> {
// 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).