diff --git a/crates/core/src/hast_to_swc_ast/decode_xml.rs b/crates/core/src/hast_to_swc_ast/decode_xml.rs index 3c917e2..cb3571c 100644 --- a/crates/core/src/hast_to_swc_ast/decode_xml.rs +++ b/crates/core/src/hast_to_swc_ast/decode_xml.rs @@ -1,7 +1,7 @@ pub fn decode_xml(s: &str) -> String { let bytes = s.as_bytes(); - let mut ret = String::new(); + let mut ret = String::with_capacity(s.len()); let mut cur_idx = 0; let mut last_idx = 0; diff --git a/crates/core/src/hast_to_swc_ast/string_to_object_style.rs b/crates/core/src/hast_to_swc_ast/string_to_object_style.rs index 79fb5ba..58f1385 100644 --- a/crates/core/src/hast_to_swc_ast/string_to_object_style.rs +++ b/crates/core/src/hast_to_swc_ast/string_to_object_style.rs @@ -1,16 +1,16 @@ +use std::borrow::Cow; + use lazy_static::lazy_static; use regex::{Captures, Regex}; use swc_core::{common::DUMMY_SP, ecma::ast::*}; use super::util::*; -pub fn hyphen_to_camel_case(s: &str) -> String { +pub fn hyphen_to_camel_case(s: &str) -> Cow { lazy_static! { static ref HYPHEN_REGEX: Regex = Regex::new(r#"-(.)"#).unwrap(); } - HYPHEN_REGEX - .replace_all(s, |caps: &Captures| caps[1].to_uppercase()) - .into() + HYPHEN_REGEX.replace_all(s, |caps: &Captures| caps[1].to_uppercase()) } // Format style key into JSX style object key.