From 6ff78962b3d4dd5350fdeb49398d42e8fa3a8ea3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 28 Sep 2020 19:06:51 +0200 Subject: Microoptimize --- crates/assists/src/handlers/invert_if.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'crates/assists') 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<()> { 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()); }) -- cgit v1.2.3