Skip to content

Commit

Permalink
Remove usage of ARc
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Jan 14, 2025
1 parent 9921098 commit c21adcb
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions crates/swc_ecma_usage_analyzer/src/alias/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(clippy::needless_update)]

use std::{cell::RefCell, sync::Arc};
use std::cell::RefCell;

use rustc_hash::FxHashSet;
use swc_common::{collections::AHashSet, SyntaxContext};
Expand Down Expand Up @@ -81,7 +81,7 @@ where
.map(|m| SyntaxContext::empty().apply_mark(m.unresolved_mark));
let decls = collect_decls(node);

let accesses: Arc<ThreadLocal<RefCell<FxHashSet<Access>>>> = Arc::default();
let accesses: ThreadLocal<RefCell<FxHashSet<Access>>> = Default::default();

{
let mut visitor = InfectionCollector {
Expand All @@ -93,18 +93,13 @@ where
track_expr_ident: true,
..Default::default()
},
accesses: accesses.clone(),
accesses: &accesses,
};

node.visit_with(&mut visitor);
}

Arc::try_unwrap(accesses)
.map_err(|_| {})
.unwrap()
.into_iter()
.flat_map(RefCell::into_inner)
.collect()
accesses.into_iter().flat_map(RefCell::into_inner).collect()
})
}

Expand All @@ -117,15 +112,12 @@ pub struct InfectionCollector<'a> {

ctx: Ctx,

accesses: Arc<ThreadLocal<RefCell<FxHashSet<Access>>>>,
accesses: &'a ThreadLocal<RefCell<FxHashSet<Access>>>,
}

impl Parallel for InfectionCollector<'_> {
fn create(&self) -> Self {
Self {
accesses: self.accesses.clone(),
..*self
}
Self { ..*self }
}

fn merge(&mut self, _: Self) {}
Expand Down

0 comments on commit c21adcb

Please sign in to comment.