Skip to content

Commit 1771222

Browse files
authoredFeb 21, 2025··
refactor(atoms): Rename FastAtom to UnsafeAtom (#10070)
**Description:** `UnsafeAtom` is a better name, because it's not only fast.
1 parent 6a90b1f commit 1771222

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed
 

‎.changeset/two-jeans-itch.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
swc_atoms: major
3+
---
4+
5+
refactor(atoms): Rename `FastAtom` to `UnsafeAtom`

‎crates/swc_atoms/src/fast.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,34 @@ use std::{
55

66
use crate::Atom;
77

8-
/// FastAtom is a wrapper around [Atom] that does not allocate, but extremely
8+
/// UnsafeAtom is a wrapper around [Atom] that does not allocate, but extremely
99
/// unsafe.
1010
///
1111
/// Do not use this unless you know what you are doing.
1212
///
1313
/// **Currently, it's considered as a unstable API and may be changed in the
1414
/// future without a semver bump.**
1515
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
16-
pub struct FastAtom(ManuallyDrop<Atom>);
16+
pub struct UnsafeAtom(ManuallyDrop<Atom>);
1717

18-
impl FastAtom {
18+
impl UnsafeAtom {
1919
/// # Safety
2020
///
2121
/// - You should ensure that the passed `atom` is not freed.
2222
///
2323
/// Some simple solutions to ensure this are
2424
///
2525
/// - Collect all [Atom] and store them somewhere while you are using
26-
/// [FastAtom]
27-
/// - Use [FastAtom] only for short-lived operations where all [Atom] is
26+
/// [UnsafeAtom]
27+
/// - Use [UnsafeAtom] only for short-lived operations where all [Atom] is
2828
/// stored in AST and ensure that the AST is not dropped.
2929
#[inline]
3030
pub unsafe fn new(atom: &Atom) -> Self {
3131
Self(ManuallyDrop::new(transmute_copy(atom)))
3232
}
3333
}
3434

35-
impl Deref for FastAtom {
35+
impl Deref for UnsafeAtom {
3636
type Target = Atom;
3737

3838
#[inline]
@@ -41,14 +41,14 @@ impl Deref for FastAtom {
4141
}
4242
}
4343

44-
impl Clone for FastAtom {
44+
impl Clone for UnsafeAtom {
4545
#[inline]
4646
fn clone(&self) -> Self {
4747
unsafe { Self::new(&self.0) }
4848
}
4949
}
5050

51-
impl PartialEq<Atom> for FastAtom {
51+
impl PartialEq<Atom> for UnsafeAtom {
5252
#[inline]
5353
fn eq(&self, other: &Atom) -> bool {
5454
*self.0 == *other

‎crates/swc_atoms/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ use once_cell::sync::Lazy;
2222
use serde::Serializer;
2323

2424
pub use self::{atom as js_word, Atom as JsWord};
25+
pub use crate::fast::UnsafeAtom;
2526

26-
pub mod fast;
27+
mod fast;
2728

2829
/// Clone-on-write string.
2930
///

‎crates/swc_ecma_ast/src/ident.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{
55
};
66

77
use phf::phf_set;
8-
use swc_atoms::{fast::FastAtom, js_word, Atom};
8+
use swc_atoms::{js_word, Atom, UnsafeAtom};
99
use swc_common::{
1010
ast_node, util::take::Take, BytePos, EqIgnoreSpan, Mark, Span, Spanned, SyntaxContext, DUMMY_SP,
1111
};
@@ -475,30 +475,30 @@ impl From<IdentName> for BindingIdent {
475475
///
476476
/// **Currently, it's considered as a unstable API and may be changed in the
477477
/// future without a semver bump.**
478-
pub type UnsafeId = (FastAtom, SyntaxContext);
478+
pub type UnsafeId = (UnsafeAtom, SyntaxContext);
479479

480480
/// This is extremely unsafe so don't use it unless you know what you are doing.
481481
///
482482
/// # Safety
483483
///
484-
/// See [`FastAtom::new`] for constraints.
484+
/// See [`UnsafeAtom::new`] for constraints.
485485
///
486486
/// **Currently, it's considered as a unstable API and may be changed in the
487487
/// future without a semver bump.**
488488
pub unsafe fn unsafe_id(id: &Id) -> UnsafeId {
489-
(FastAtom::new(&id.0), id.1)
489+
(UnsafeAtom::new(&id.0), id.1)
490490
}
491491

492492
/// This is extremely unsafe so don't use it unless you know what you are doing.
493493
///
494494
/// # Safety
495495
///
496-
/// See [`FastAtom::new`] for constraints.
496+
/// See [`UnsafeAtom::new`] for constraints.
497497
///
498498
/// **Currently, it's considered as a unstable API and may be changed in the
499499
/// future without a semver bump.**
500500
pub unsafe fn unsafe_id_from_ident(id: &Ident) -> UnsafeId {
501-
(FastAtom::new(&id.sym), id.ctxt)
501+
(UnsafeAtom::new(&id.sym), id.ctxt)
502502
}
503503

504504
/// See [Ident] for documentation.

0 commit comments

Comments
 (0)
Please sign in to comment.