mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
perf(semantic): skip escape checks for unescaped strings (#28507)
Account for both quotes when comparing raw and cooked string lengths, skipping escape scans for unescaped strict strings. AI-assisted (Codex).
This commit is contained in:
1 parent
babf44cc96
commit
235ca3bd25
1 file changed
+3
-1
@@ -419,7 +419,9 @@ pub fn check_string_literal(lit: &StringLiteral, ctx: &SemanticBuilder<'_>) {
|
||||
}
|
||||
let raw = lit.span.source_text(ctx.source_text);
|
||||
let raw_len = raw.len();
|
||||
if raw_len != lit.value.len() {
|
||||
// Quotes contribute two bytes, and every escape contracts the cooked WTF-8 value.
|
||||
// Equal content lengths therefore prove that there are no escapes to check.
|
||||
if raw_len != lit.value.len() + 2 {
|
||||
if raw_len >= MIN_STRING_SIZE_FOR_BATCH_CHECK {
|
||||
let raw_bytes = raw.as_bytes();
|
||||
// Exclude the last byte (closing quote) from the search haystack.
|
||||
|
||||
Reference in new issue
Block a user