mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 22:22:34 +03:00
perf(css/minifier): Improve performance (#6583)
This commit is contained in:
parent
824979f92b
commit
78955995a2
@ -482,12 +482,23 @@ impl Compressor {
|
||||
|
||||
pub(super) fn compress_simple_block(&mut self, simple_block: &mut SimpleBlock) {
|
||||
let mut names: AHashMap<Name, isize> = Default::default();
|
||||
let mut prev_rule: Option<ComponentValue> = None;
|
||||
let mut prev_rule_idx = None;
|
||||
let mut remove_rules_list = vec![];
|
||||
let mut prev_index = 0;
|
||||
let mut index = 0;
|
||||
|
||||
simple_block.value.retain_mut(|rule| {
|
||||
for index in 0..simple_block.value.len() {
|
||||
// We need two &mut
|
||||
let (a, b) = simple_block.value.split_at_mut(index);
|
||||
|
||||
let mut prev_rule = match prev_rule_idx {
|
||||
Some(idx) => a.get_mut(idx),
|
||||
None => None,
|
||||
};
|
||||
let rule = match b.first_mut() {
|
||||
Some(v) => v,
|
||||
None => continue,
|
||||
};
|
||||
|
||||
let result = match rule {
|
||||
ComponentValue::Rule(box Rule::AtRule(box AtRule {
|
||||
block: Some(block), ..
|
||||
@ -600,24 +611,24 @@ impl Compressor {
|
||||
if self.is_mergeable_at_rule(at_rule) =>
|
||||
{
|
||||
prev_index = index;
|
||||
prev_rule = Some(rule.clone());
|
||||
prev_rule_idx = Some(index);
|
||||
}
|
||||
|
||||
ComponentValue::Rule(box Rule::QualifiedRule(_))
|
||||
| ComponentValue::StyleBlock(box StyleBlock::QualifiedRule(_)) => {
|
||||
prev_index = index;
|
||||
prev_rule = Some(rule.clone());
|
||||
prev_rule_idx = Some(index);
|
||||
}
|
||||
_ => {
|
||||
prev_rule = None;
|
||||
prev_rule_idx = None;
|
||||
}
|
||||
}
|
||||
|
||||
index += 1;
|
||||
}
|
||||
|
||||
result
|
||||
});
|
||||
if !result {
|
||||
remove_rules_list.push(index);
|
||||
}
|
||||
}
|
||||
|
||||
if !names.is_empty() {
|
||||
self.discard_overridden(
|
||||
|
Loading…
Reference in New Issue
Block a user