aboutsummaryrefslogtreecommitdiff
path: root/crates/assists
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-09-28 18:06:51 +0100
committerAleksey Kladov <[email protected]>2020-09-28 18:06:51 +0100
commit6ff78962b3d4dd5350fdeb49398d42e8fa3a8ea3 (patch)
tree554dc3e48db1d5d5bf26cffe46920855da017c99 /crates/assists
parenteb79c2094f4328088b13a3dcf5fe253806c73c86 (diff)
Microoptimize
Diffstat (limited to 'crates/assists')
-rw-r--r--crates/assists/src/handlers/invert_if.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/crates/assists/src/handlers/invert_if.rs b/crates/assists/src/handlers/invert_if.rs
index 294256297..461fcf862 100644
--- a/crates/assists/src/handlers/invert_if.rs
+++ b/crates/assists/src/handlers/invert_if.rs
@@ -49,13 +49,14 @@ pub(crate) fn invert_if(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
49 ast::ElseBranch::IfExpr(_) => return None, 49 ast::ElseBranch::IfExpr(_) => return None,
50 }; 50 };
51 51
52 let cond_range = cond.syntax().text_range();
53 let flip_cond = invert_boolean_expression(cond);
54 let else_node = else_block.syntax();
55 let else_range = else_node.text_range();
56 let then_range = then_node.text_range();
57 acc.add(AssistId("invert_if", AssistKind::RefactorRewrite), "Invert if", if_range, |edit| { 52 acc.add(AssistId("invert_if", AssistKind::RefactorRewrite), "Invert if", if_range, |edit| {
58 edit.replace(cond_range, flip_cond.syntax().text()); 53 let flip_cond = invert_boolean_expression(cond.clone());
54 edit.replace_ast(cond, flip_cond);
55
56 let else_node = else_block.syntax();
57 let else_range = else_node.text_range();
58 let then_range = then_node.text_range();
59
59 edit.replace(else_range, then_node.text()); 60 edit.replace(else_range, then_node.text());
60 edit.replace(then_range, else_node.text()); 61 edit.replace(then_range, else_node.text());
61 }) 62 })