From 42c24ff25f391a1e3662ce226d510aedc9d1f0e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Tue, 29 Dec 2020 14:35:49 +0200 Subject: Avoid a couple of allocations --- crates/assists/src/handlers/extract_variable.rs | 2 +- .../handlers/replace_derive_with_manual_impl.rs | 31 +++++++++++----------- 2 files changed, 17 insertions(+), 16 deletions(-) (limited to 'crates/assists/src/handlers') diff --git a/crates/assists/src/handlers/extract_variable.rs b/crates/assists/src/handlers/extract_variable.rs index d2ae137cd..9957012fe 100644 --- a/crates/assists/src/handlers/extract_variable.rs +++ b/crates/assists/src/handlers/extract_variable.rs @@ -91,7 +91,7 @@ pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext) -> Option // extra newlines in the indent block let text = indent.text(); if text.starts_with('\n') { - buf.push_str("\n"); + buf.push('\n'); buf.push_str(text.trim_start_matches('\n')); } else { buf.push_str(text); diff --git a/crates/assists/src/handlers/replace_derive_with_manual_impl.rs b/crates/assists/src/handlers/replace_derive_with_manual_impl.rs index 4d6a1956b..cb7a5c104 100644 --- a/crates/assists/src/handlers/replace_derive_with_manual_impl.rs +++ b/crates/assists/src/handlers/replace_derive_with_manual_impl.rs @@ -62,21 +62,22 @@ pub(crate) fn replace_derive_with_manual_impl( let current_module = ctx.sema.scope(annotated_name.syntax()).module()?; let current_crate = current_module.krate(); - let found_traits = - imports_locator::find_exact_imports(&ctx.sema, current_crate, trait_token.text()) - .filter_map( - |candidate: either::Either| match candidate { - either::Either::Left(hir::ModuleDef::Trait(trait_)) => Some(trait_), - _ => None, - }, - ) - .flat_map(|trait_| { - current_module - .find_use_path(ctx.sema.db, hir::ModuleDef::Trait(trait_)) - .as_ref() - .map(mod_path_to_ast) - .zip(Some(trait_)) - }); + let found_traits = imports_locator::find_exact_imports( + &ctx.sema, + current_crate, + trait_token.text().to_string(), + ) + .filter_map(|candidate: either::Either| match candidate { + either::Either::Left(hir::ModuleDef::Trait(trait_)) => Some(trait_), + _ => None, + }) + .flat_map(|trait_| { + current_module + .find_use_path(ctx.sema.db, hir::ModuleDef::Trait(trait_)) + .as_ref() + .map(mod_path_to_ast) + .zip(Some(trait_)) + }); let mut no_traits_found = true; for (trait_path, trait_) in found_traits.inspect(|_| no_traits_found = false) { -- cgit v1.2.3