Skip to content

Commit

Permalink
feat(span): add Atom::r#static (#8479)
Browse files Browse the repository at this point in the history
This allows

```rs
const TYPEOF_UNDEFINED: Atom<'static> = Atom::r#static("undefined");

#[derive(Clone, Copy)]
enum Value<'a> {
  /// Not `Atom<'a>`, which takes one more byte
  StringLiteral(&'a Atom<'a>),
  // ...
}

fn get_typeof<'a>(value: Value<'a>) -> Value<'a> {
  if ... {
    return Value::StringLiteral(&TYPEOF_UNDEFINED);
  }
}
```
  • Loading branch information
kermanx authored Jan 14, 2025
1 parent c444de8 commit 9d550aa
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion crates/oxc_span/src/atom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ use crate::{cmp::ContentEq, hash::ContentHash, CompactStr};
pub struct Atom<'a>(&'a str);

impl Atom<'static> {
/// Get an [`Atom`] containing a static string.
#[inline]
pub const fn r#static(s: &'static str) -> Self {
Atom(s)
}

/// Get an [`Atom`] containing the empty string (`""`).
#[inline]
pub const fn empty() -> Self {
Atom("")
Self::r#static("")
}
}

Expand Down

0 comments on commit 9d550aa

Please sign in to comment.