Skip to content

Commit

Permalink
refactor(span): simplify Atom (#2630)
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Mar 6, 2024
1 parent cb4e054 commit b2de57a
Showing 1 changed file with 7 additions and 25 deletions.
32 changes: 7 additions & 25 deletions crates/oxc_span/src/atom.rs
Expand Up @@ -23,9 +23,7 @@ pub const MAX_INLINE_LEN: usize = 16;
/// Use [CompactStr] with [Atom::to_compact_str] or [Atom::into_compact_str] for the
/// lifetimeless form.
#[derive(Clone, Eq)]
pub enum Atom<'a> {
Arena(&'a str),
}
pub struct Atom<'a>(&'a str);

#[cfg(feature = "serde")]
impl<'a> Serialize for Atom<'a> {
Expand All @@ -40,36 +38,28 @@ impl<'a> Serialize for Atom<'a> {
impl<'a> Atom<'a> {
#[inline]
pub fn as_str(&self) -> &str {
match self {
Self::Arena(s) => s,
}
self.0
}

#[inline]
pub fn into_string(self) -> String {
match self {
Self::Arena(s) => String::from(s),
}
String::from(self.as_str())
}

#[inline]
pub fn into_compact_str(self) -> CompactStr {
match self {
Self::Arena(s) => CompactStr::new(s),
}
CompactStr::new(self.as_str())
}

#[inline]
pub fn to_compact_str(&self) -> CompactStr {
match &self {
Self::Arena(s) => CompactStr::new(s),
}
CompactStr::new(self.as_str())
}
}

impl<'a> From<&'a str> for Atom<'a> {
fn from(s: &'a str) -> Self {
Self::Arena(s)
Self(s)
}
}

Expand Down Expand Up @@ -107,9 +97,7 @@ impl<'a> PartialEq<Atom<'a>> for &str {

impl<'a> hash::Hash for Atom<'a> {
fn hash<H: hash::Hasher>(&self, hasher: &mut H) {
match self {
Self::Arena(s) => s.hash(hasher),
}
self.as_str().hash(hasher);
}
}

Expand Down Expand Up @@ -206,12 +194,6 @@ impl From<String> for CompactStr {
}
}

impl From<CompactString> for CompactStr {
fn from(s: CompactString) -> Self {
Self(s)
}
}

impl Deref for CompactStr {
type Target = str;

Expand Down

0 comments on commit b2de57a

Please sign in to comment.