From 7cd46cb70b27c8e09d2d0088053a6542aaa3f6d5 Mon Sep 17 00:00:00 2001 From: leaysgur <6259812+leaysgur@users.noreply.github.com> Date: Mon, 2 Nov 2026 05:03:29 +0000 Subject: [PATCH] perf(formatter_htmlish): search script end tags by `<` in embedded (#28704) Optimize `( /// printed as `<\/script`, where `\/` means `/` (in a JS string or template, and in JSON). /// /// A nested HTML part prints its end tags as one text (`tag.rs`), so none is split across texts. +/// A JSX closing tag is (`` prints ``), left as is: rare, and JSX has no escape for it. fn escape_script_end<'a>( ir: ArenaVec<'a, FormatElement<'a>>, f: &HtmlishFormatter<'_, 'a>, @@ -191,12 +192,13 @@ fn escape_script_end<'a>( let allocator = f.allocator(); let indent_width = f.options().indent_width(); map_text_in_ir(ir, allocator, &mut |text, out| { + let bytes = text.as_bytes(); let is_script_end = |i: usize| { - let bytes = &text.as_bytes()[i + 2..]; - bytes.get(..6).is_some_and(|name| name.eq_ignore_ascii_case(b"script")) - && !bytes.get(6).is_some_and(|&b| b.is_ascii_alphanumeric() || b == b'_') + bytes.get(i + 1..i + 8).is_some_and(|tag| tag.eq_ignore_ascii_case(b"/script")) + && !bytes.get(i + 8).is_some_and(|&b| b.is_ascii_alphanumeric() || b == b'_') }; - let mut ends = text.match_indices("