mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
refactor(codegen): reduce allocation for print_unquoted_str (#3525)
This commit is contained in:
parent
9706c3b533
commit
ddac2a0e12
2 changed files with 7 additions and 7 deletions
|
|
@ -1265,12 +1265,12 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for RegExpLiteral<'a> {
|
|||
}
|
||||
|
||||
fn print_unquoted_str<const MINIFY: bool>(s: &str, quote: char, p: &mut Codegen<{ MINIFY }>) {
|
||||
let mut chars = s.chars();
|
||||
let mut chars = s.chars().peekable();
|
||||
|
||||
while let Some(c) = chars.next() {
|
||||
match c {
|
||||
'\x00' => {
|
||||
if chars.clone().next().is_some_and(|next| next.is_ascii_digit()) {
|
||||
if chars.peek().is_some_and(|&next| next.is_ascii_digit()) {
|
||||
p.print_str(b"\\x00");
|
||||
} else {
|
||||
p.print_str(b"\\0");
|
||||
|
|
@ -1325,7 +1325,7 @@ fn print_unquoted_str<const MINIFY: bool>(s: &str, quote: char, p: &mut Codegen<
|
|||
}
|
||||
}
|
||||
'$' => {
|
||||
if chars.clone().next().is_some_and(|next| next == '{') {
|
||||
if chars.peek().is_some_and(|&next| next == '{') {
|
||||
p.print_str(b"\\$");
|
||||
} else {
|
||||
p.print_str(b"$");
|
||||
|
|
|
|||
|
|
@ -61,12 +61,12 @@ fn string() {
|
|||
test("let x = '\x071'", "let x = '\\x071';\n", None);
|
||||
test("let x = '\\7'", "let x = '\\x07';\n", None);
|
||||
test("let x = '\\7!'", "let x = '\\x07!';\n", None);
|
||||
// test( "let x = '\\01'", "let x = '\x01';\n", None);
|
||||
// test( "let x = '\x10'", "let x = '\x10';\n", None);
|
||||
// test( "let x = '\\x10'", "let x = '\x10';\n", None);
|
||||
test("let x = '\\01'", "let x = '\x01';\n", None);
|
||||
test("let x = '\x10'", "let x = '\x10';\n", None);
|
||||
test("let x = '\\x10'", "let x = '\x10';\n", None);
|
||||
test("let x = '\x1B'", "let x = '\\x1B';\n", None);
|
||||
test("let x = '\\x1B'", "let x = '\\x1B';\n", None);
|
||||
// test( r#"let x = '\uABCD'"#, r#"let x = "\uABCD";"#, None);
|
||||
test("let x = '\\uABCD'", "let x = 'ꯍ';\n", None);
|
||||
// test( "let x = '\\uABCD'", r#"let x = '\uABCD';\n"#, None);
|
||||
// test( r#"let x = '\U000123AB'"#, r#"let x = '\U000123AB';\n"#, None);
|
||||
// test( "let x = '\\u{123AB}'", r#"let x = '\U000123AB';\n"#, None);
|
||||
|
|
|
|||
Loading…
Reference in a new issue