Skip to content

Commit

Permalink
merge_data
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Jan 12, 2025
1 parent 3c8d37f commit 593d5e9
Showing 1 changed file with 23 additions and 34 deletions.
57 changes: 23 additions & 34 deletions crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -971,24 +971,8 @@ impl VisitMut for TreeShaker {
};
m.visit_with(&mut analyzer);
}
let data = Arc::try_unwrap(data)
.map_err(|_| {})
.unwrap()
.into_iter()
.map(|d| d.into_inner())
.map(|mut data| {
data.subtract_cycles();
data
})
.collect::<Vec<_>>();
let mut merged = Data::default();

for data in data {
merged.used_names.extend(data.used_names);
merged.entry_ids.extend(data.entry_ids);
}

self.data = Arc::new(merged);
self.data = Arc::new(merge_data(data));

m.visit_mut_children_with(self);
})
Expand Down Expand Up @@ -1050,24 +1034,8 @@ impl VisitMut for TreeShaker {
};
m.visit_with(&mut analyzer);
}
let data = Arc::try_unwrap(data)
.map_err(|_| {})
.unwrap()
.into_iter()
.map(|d| d.into_inner())
.map(|mut data| {
data.subtract_cycles();
data
})
.collect::<Vec<_>>();
let mut merged = Data::default();

for data in data {
merged.used_names.extend(data.used_names);
merged.entry_ids.extend(data.entry_ids);
}

self.data = Arc::new(merged);
self.data = Arc::new(merge_data(data));

m.visit_mut_children_with(self);
})
Expand Down Expand Up @@ -1202,6 +1170,27 @@ impl VisitMut for TreeShaker {
}
}

fn merge_data(data: Arc<ThreadLocal<RefCell<Data>>>) -> Data {
let data = Arc::try_unwrap(data)
.map_err(|_| {})
.unwrap()
.into_iter()
.map(|d| d.into_inner())
.map(|mut data| {
data.subtract_cycles();
data
})
.collect::<Vec<_>>();
let mut merged = Data::default();

for data in data {
merged.used_names.extend(data.used_names);
merged.entry_ids.extend(data.entry_ids);
}

merged
}

impl Scope<'_> {
/// Returns true if it's not in a function or class.
fn is_ast_path_empty(&self) -> bool {
Expand Down

0 comments on commit 593d5e9

Please sign in to comment.