mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
feat(span): add Atom::r#static (#8479)
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);
}
}
```
This commit is contained in:
parent
c444de8be1
commit
9d550aacaf
1 changed files with 7 additions and 1 deletions
|
|
@ -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("")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue