New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf(css/minifier): Remove more redundant clones #6580
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kdy1
commented
Dec 6, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
swc-bump:
- swc_css_ast
Please use: fn discard_overridden(
&self,
parent_node: ParentNode,
names: &mut AHashMap<Name, isize>,
remove_rules_list: &mut Vec<usize>,
) {
let mut discarder = |at_rule: &AtRule| match &at_rule.prelude {
Some(box AtRulePrelude::CounterStylePrelude(CustomIdent { value: name, .. })) => {
if let Some(counter) = names.get_mut(&Name::CounterStyle(name.clone())) {
if *counter > 1 {
*counter -= 1;
false
} else {
true
}
} else {
false
}
}
Some(box AtRulePrelude::KeyframesPrelude(KeyframesName::CustomIdent(
box CustomIdent { value: name, .. },
)))
| Some(box AtRulePrelude::KeyframesPrelude(KeyframesName::Str(box Str {
value: name,
..
}))) => {
let counter = names.get_mut(&Name::Keyframes(
self.get_at_rule_name(at_rule),
name.clone(),
));
if let Some(counter) = counter {
if *counter > 1 {
*counter -= 1;
false
} else {
true
}
} else {
false
}
}
_ => true,
};
match parent_node {
ParentNode::Stylesheet(stylesheet) => {
for index in 0..stylesheet.rules.len() {
let node = stylesheet.rules.get(index);
match node {
Some(Rule::AtRule(box at_rule)) => {
if !discarder(&at_rule) {
remove_rules_list.push(index);
}
},
_ => { },
}
}
}
ParentNode::SimpleBlock(simple_block) => {
for index in 0..simple_block.value.len() {
let node = simple_block.value.get(index);
match node {
Some(ComponentValue::Rule(box Rule::AtRule(box at_rule))) => {
if !discarder(&at_rule) {
remove_rules_list.push(index);
}
},
_ => { },
}
}
}
}
} and self.discard_overridden(
ParentNode::Stylesheet(stylesheet),
&mut names,
&mut remove_rules_list,
); |
kdy1
changed the title
perf(css/minifier): Remove more redundant clone
perf(css/minifier): Remove more redundant clones
Dec 6, 2022
swc-bot
reviewed
Dec 6, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Automated review comment generated by auto-rebase script
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
Related issue (if exists):