From 36895d96949eded85fe674c2a6585cba187e0aef Mon Sep 17 00:00:00 2001 From: g4lb Date: Sat, 7 Nov 2026 03:30:39 +0200 Subject: [PATCH] perf(tokenizer): scan quoted attribute values in one loop --- src/Tokenizer.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Tokenizer.ts b/src/Tokenizer.ts index 6f983e1b..0542d561 100644 --- a/src/Tokenizer.ts +++ b/src/Tokenizer.ts @@ -687,8 +687,20 @@ export default class Tokenizer { this.index + 1, ); this.state = State.BeforeAttributeName; - } else if (this.decodeEntities && c === CharCodes.Amp) { - this.startEntity(); + } else if (this.decodeEntities) { + if (c === CharCodes.Amp) { + this.startEntity(); + return; + } + // Skip to the next quote or `&`, or the end of the buffer. + const { buffer, offset } = this; + let index = this.index - offset + 1; + while (index < buffer.length) { + const next = buffer.charCodeAt(index); + if (next === quote || next === CharCodes.Amp) break; + index++; + } + this.index = index + offset - 1; } } private stateInAttributeValueDoubleQuotes(c: number): void {