mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
perf(formatter_htmlish): use char to escape attr quotes (#28697)
single character `&str` with `cow_replaces` is not efficient, `char` is enough here.
This commit is contained in:
1 parent
fef809a7f3
commit
ceb26be83c
1 file changed
+4
-2
@@ -198,8 +198,10 @@ fn write_tailwind_classes<'a>(
|
||||
fn write_quoted_value<'a>(raw: &'a str, f: &mut HtmlishFormatter<'_, 'a>) {
|
||||
let doubles = raw.bytes().filter(|&b| b == b'"').count();
|
||||
let singles = raw.bytes().filter(|&b| b == b'\'').count();
|
||||
let (quote, escaped) = if doubles > singles { ("'", "'") } else { ("\"", """) };
|
||||
let printed = arena_cow_str(&raw.cow_replace(quote, escaped), f);
|
||||
// A `char` pattern: a 1-char `&str` would build a substring searcher for every value
|
||||
let (quote, pattern, escaped) =
|
||||
if doubles > singles { ("'", '\'', "'") } else { ("\"", '"', """) };
|
||||
let printed = arena_cow_str(&raw.cow_replace(pattern, escaped), f);
|
||||
write!(f, [text(quote), text(printed), text(quote)]);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user