mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 09:27:27 +00:00
Microoptimize
This commit is contained in:
parent
eb79c2094f
commit
6ff78962b3
1 changed files with 7 additions and 6 deletions
|
@ -49,13 +49,14 @@ pub(crate) fn invert_if(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
|
|||
ast::ElseBranch::IfExpr(_) => return None,
|
||||
};
|
||||
|
||||
let cond_range = cond.syntax().text_range();
|
||||
let flip_cond = invert_boolean_expression(cond);
|
||||
let else_node = else_block.syntax();
|
||||
let else_range = else_node.text_range();
|
||||
let then_range = then_node.text_range();
|
||||
acc.add(AssistId("invert_if", AssistKind::RefactorRewrite), "Invert if", if_range, |edit| {
|
||||
edit.replace(cond_range, flip_cond.syntax().text());
|
||||
let flip_cond = invert_boolean_expression(cond.clone());
|
||||
edit.replace_ast(cond, flip_cond);
|
||||
|
||||
let else_node = else_block.syntax();
|
||||
let else_range = else_node.text_range();
|
||||
let then_range = then_node.text_range();
|
||||
|
||||
edit.replace(else_range, then_node.text());
|
||||
edit.replace(then_range, else_node.text());
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue