mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 22:56:11 +03:00
perf(es/minifier): Add some fast-path to the MultiReplacer
(#4408)
This commit is contained in:
parent
5a8250610a
commit
4c9e5c01ef
@ -23,8 +23,8 @@ fn main() {
|
||||
|
||||
testing::run_test2(false, |cm, handler| {
|
||||
GLOBALS.with(|globals| {
|
||||
files
|
||||
.into_par_iter()
|
||||
let _ = files
|
||||
.into_iter()
|
||||
.map(|path| -> Result<_> {
|
||||
GLOBALS.set(globals, || {
|
||||
let fm = cm.load_file(&path).expect("failed to load file");
|
||||
|
@ -8,4 +8,4 @@
|
||||
|
||||
|
||||
export RUST_LOG=off
|
||||
cargo profile instruments -t time --example minify-all --release -- $@
|
||||
cargo profile instruments -t time --example minify-all --features swc_common/perf --release -- $@
|
@ -250,8 +250,15 @@ impl VisitMut for MultiReplacer<'_> {
|
||||
}
|
||||
|
||||
fn visit_mut_expr(&mut self, e: &mut Expr) {
|
||||
if self.vars.is_empty() {
|
||||
return;
|
||||
}
|
||||
e.visit_mut_children_with(self);
|
||||
|
||||
if self.vars.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
if matches!(self.mode, MultiReplacerMode::Normal) {
|
||||
if let Expr::Ident(i) = e {
|
||||
if let Some(new) = self.var(&i.to_id()) {
|
||||
@ -286,6 +293,7 @@ impl VisitMut for MultiReplacer<'_> {
|
||||
fn visit_mut_prop(&mut self, p: &mut Prop) {
|
||||
p.visit_mut_children_with(self);
|
||||
|
||||
if matches!(self.mode, MultiReplacerMode::Normal) {
|
||||
if let Prop::Shorthand(i) = p {
|
||||
if let Some(value) = self.var(&i.to_id()) {
|
||||
debug!("multi-replacer: Replaced `{}` as shorthand", i);
|
||||
@ -303,6 +311,7 @@ impl VisitMut for MultiReplacer<'_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn replace_id_with_expr<N>(node: &mut N, from: Id, to: Box<Expr>) -> Option<Box<Expr>>
|
||||
where
|
||||
|
Loading…
Reference in New Issue
Block a user