diff --git a/Cargo.lock b/Cargo.lock index eafbb8042..8e3cab7e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -821,15 +821,6 @@ dependencies = [ "serde", ] -[[package]] -name = "inlinable_string" -version = "0.1.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8fae54786f62fb2918dcfae3d568594e50eb9b5c25bf04371af6fe7516452fb" -dependencies = [ - "serde", -] - [[package]] name = "insta" version = "1.35.1" @@ -1669,7 +1660,6 @@ name = "oxc_span" version = "0.8.0" dependencies = [ "compact_str", - "inlinable_string", "miette", "serde", "tsify", diff --git a/crates/oxc_semantic/src/binder.rs b/crates/oxc_semantic/src/binder.rs index 42f0321da..a90486a24 100644 --- a/crates/oxc_semantic/src/binder.rs +++ b/crates/oxc_semantic/src/binder.rs @@ -345,7 +345,7 @@ impl<'a> Binder for TSEnumMember<'a> { let name = match &self.id { TSEnumMemberName::Identifier(id) => id.name.clone(), TSEnumMemberName::StringLiteral(s) => s.value.clone(), - TSEnumMemberName::NumericLiteral(n) => Atom::new_inline(&n.value.to_string()), + TSEnumMemberName::NumericLiteral(n) => Atom::from(n.value.to_string()), TSEnumMemberName::ComputedPropertyName(_) => panic!("TODO: implement"), }; builder.declare_symbol( diff --git a/crates/oxc_span/Cargo.toml b/crates/oxc_span/Cargo.toml index 0b060e978..3d2d1943a 100644 --- a/crates/oxc_span/Cargo.toml +++ b/crates/oxc_span/Cargo.toml @@ -20,8 +20,7 @@ doctest = false [dependencies] miette = { workspace = true } -inlinable_string = "0.1.15" -compact_str = { version = "0.7.1", features = ["serde"] } +compact_str = { version = "0.7.1" } tsify = { workspace = true, optional = true } wasm-bindgen = { workspace = true, optional = true } @@ -30,5 +29,5 @@ serde = { workspace = true, features = ["derive"], optional = true } [features] default = [] -serde = ["dep:serde", "inlinable_string/serde"] +serde = ["dep:serde", "compact_str/serde"] wasm = ["dep:tsify", "dep:wasm-bindgen"] diff --git a/crates/oxc_span/src/atom.rs b/crates/oxc_span/src/atom.rs index d14520bf5..d27075ce1 100644 --- a/crates/oxc_span/src/atom.rs +++ b/crates/oxc_span/src/atom.rs @@ -8,7 +8,6 @@ use std::{ use serde::{Serialize, Serializer}; use compact_str::CompactString; -use inlinable_string::inline_string::{InlineString, INLINE_STRING_CAPACITY}; const BASE54_CHARS: &[u8; 64] = b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_0123456789"; @@ -29,16 +28,10 @@ export type CompactString = string; pub struct Atom<'a>(AtomImpl<'a>); /// Immutable Inlinable String -/// -/// https://github.com/fitzgen/inlinable_string/blob/master/src/lib.rs #[derive(Clone, Eq, PartialEq)] enum AtomImpl<'a> { - /// A arena heap-allocated string. Arena(&'a str), - /// A heap-allocated string. - Heap(Box), - /// A small string stored inline. - Inline(InlineString), + Compact(CompactString), } #[cfg(feature = "serde")] @@ -52,16 +45,11 @@ impl<'a> Serialize for Atom<'a> { } impl<'a> Atom<'a> { - pub fn new_inline(s: &str) -> Self { - Self(AtomImpl::Inline(InlineString::from(s))) - } - #[inline] pub fn as_str(&self) -> &str { match &self.0 { AtomImpl::Arena(s) => s, - AtomImpl::Heap(s) => s, - AtomImpl::Inline(s) => s.as_ref(), + AtomImpl::Compact(s) => s.as_ref(), } } @@ -69,24 +57,23 @@ impl<'a> Atom<'a> { pub fn into_string(self) -> String { match self.0 { AtomImpl::Arena(s) => String::from(s), - AtomImpl::Heap(s) => s.to_string(), - AtomImpl::Inline(s) => s.to_string(), + AtomImpl::Compact(s) => s.to_string(), } } + #[inline] pub fn into_compact_string(self) -> CompactString { match self.0 { AtomImpl::Arena(s) => CompactString::new(s), - AtomImpl::Heap(s) => CompactString::new(s), - AtomImpl::Inline(s) => CompactString::new(s), + AtomImpl::Compact(s) => s, } } + #[inline] pub fn to_compact_string(&self) -> CompactString { match &self.0 { AtomImpl::Arena(s) => CompactString::new(s), - AtomImpl::Heap(s) => CompactString::new(s), - AtomImpl::Inline(s) => CompactString::new(s), + AtomImpl::Compact(s) => s.clone(), } } @@ -108,37 +95,25 @@ impl<'a> Atom<'a> { ret.push(BASE54_CHARS[num % base] as char); num /= base; } - Self(AtomImpl::Heap(ret.into_boxed_str())) + Self(AtomImpl::Compact(CompactString::new(ret))) } } impl<'a> From<&'a str> for Atom<'a> { fn from(s: &'a str) -> Self { - if s.len() <= INLINE_STRING_CAPACITY { - Self(AtomImpl::Inline(InlineString::from(s))) - } else { - Self(AtomImpl::Arena(s)) - } + Self(AtomImpl::Arena(s)) } } impl<'a> From for Atom<'a> { fn from(s: String) -> Self { - if s.len() <= INLINE_STRING_CAPACITY { - Self(AtomImpl::Inline(InlineString::from(s.as_str()))) - } else { - Self(AtomImpl::Heap(s.into_boxed_str())) - } + Self(AtomImpl::Compact(CompactString::from(s))) } } impl<'a> From> for Atom<'a> { fn from(s: Cow<'_, str>) -> Self { - if s.len() <= INLINE_STRING_CAPACITY { - Self(AtomImpl::Inline(InlineString::from(s.borrow()))) - } else { - Self(AtomImpl::Heap(s.into())) - } + Self(AtomImpl::Compact(CompactString::from(s))) } } @@ -151,14 +126,12 @@ impl<'a> Deref for Atom<'a> { } impl<'a> AsRef for Atom<'a> { - #[inline] fn as_ref(&self) -> &str { self.as_str() } } impl<'a> Borrow for Atom<'a> { - #[inline] fn borrow(&self) -> &str { self.as_str() } @@ -177,12 +150,10 @@ impl<'a> PartialEq> for &str { } impl<'a> hash::Hash for AtomImpl<'a> { - #[inline] fn hash(&self, hasher: &mut H) { match self { Self::Arena(s) => s.hash(hasher), - Self::Heap(s) => s.hash(hasher), - Self::Inline(s) => s.hash(hasher), + Self::Compact(s) => s.hash(hasher), } } }