Skip to content

Commit acf8ffe

Browse files
committed
as_wtf8_str
1 parent a6ce6f6 commit acf8ffe

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

crates/hstr/src/lib.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,21 @@ impl Atom {
250250
}
251251
self.clone()
252252
}
253+
254+
pub fn as_wtf8_str(&self) -> &wtf8::Wtf8 {
255+
match self.tag() {
256+
DYNAMIC_TAG => unsafe {
257+
let item = crate::dynamic::deref_from(self.unsafe_data);
258+
wtf8::Wtf8::from_bytes(transmute::<&[u8], &'static [u8]>(&item.slice))
259+
},
260+
INLINE_TAG => {
261+
let len = (self.unsafe_data.tag() & LEN_MASK) >> LEN_OFFSET;
262+
let src = self.unsafe_data.data();
263+
wtf8::Wtf8::from_bytes(&src[..(len as usize)])
264+
}
265+
_ => unsafe { debug_unreachable!() },
266+
}
267+
}
253268
}
254269

255270
impl Atom {
@@ -284,21 +299,6 @@ impl Atom {
284299
_ => unsafe { debug_unreachable!() },
285300
}
286301
}
287-
288-
fn as_wtf8_str(&self) -> &wtf8::Wtf8 {
289-
match self.tag() {
290-
DYNAMIC_TAG => unsafe {
291-
let item = crate::dynamic::deref_from(self.unsafe_data);
292-
wtf8::Wtf8::from_bytes(transmute::<&[u8], &'static [u8]>(&item.slice))
293-
},
294-
INLINE_TAG => {
295-
let len = (self.unsafe_data.tag() & LEN_MASK) >> LEN_OFFSET;
296-
let src = self.unsafe_data.data();
297-
wtf8::Wtf8::from_bytes(&src[..(len as usize)])
298-
}
299-
_ => unsafe { debug_unreachable!() },
300-
}
301-
}
302302
}
303303

304304
#[cfg(test)]

crates/swc_atoms/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ impl Atom {
7676
pub fn as_str(&self) -> &str {
7777
&self.0
7878
}
79+
80+
#[inline]
81+
pub fn as_wtf8_str(&self) -> &wtf8::Wtf8 {
82+
self.0.as_wtf8_str()
83+
}
7984
}
8085

8186
impl Deref for Atom {

crates/swc_ecma_codegen/src/lit.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ impl MacroNode for Str {
7878

7979
if es5_safe
8080
&& (!emitter.cfg.ascii_only || raw.is_ascii())
81-
&& (!emitter.cfg.inline_script
82-
|| !self.raw.as_ref().unwrap().contains("script"))
81+
&& (!emitter.cfg.inline_script || !raw.contains("script"))
8382
{
8483
emitter.wr.write_str_lit(DUMMY_SP, raw)?;
8584
return Ok(());

0 commit comments

Comments
 (0)