From 406343492c9f1741fcc3eafbb13efa42691fe0db Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Thu, 7 Mar 2019 13:36:35 +0100 Subject: Simplify calculation of missing functions Asymptotically computing a set difference is faster but in the average case we won't have more than ~10 functions. Also prefer not using hash sets as these may yield nondeterministic results. --- crates/ra_assists/src/add_missing_impl_members.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/crates/ra_assists/src/add_missing_impl_members.rs b/crates/ra_assists/src/add_missing_impl_members.rs index f121dafb2..97af6362c 100644 --- a/crates/ra_assists/src/add_missing_impl_members.rs +++ b/crates/ra_assists/src/add_missing_impl_members.rs @@ -1,5 +1,3 @@ -use std::collections::HashSet; - use crate::{Assist, AssistId, AssistCtx}; use hir::Resolver; @@ -69,14 +67,9 @@ pub(crate) fn add_missing_impl_members(mut ctx: AssistCtx) -> let trait_fns = trait_items.map(ImplItem::kind).filter_map(fn_def_opt).collect::>(); let impl_fns = impl_items.map(ImplItem::kind).filter_map(fn_def_opt).collect::>(); - let trait_fn_names = trait_fns.iter().cloned().filter_map(def_name).collect::>(); - let impl_fn_names = impl_fns.iter().cloned().filter_map(def_name).collect::>(); - - let missing_fn_names = trait_fn_names.difference(&impl_fn_names).collect::>(); let missing_fns: Vec<_> = trait_fns - .iter() - .cloned() - .filter(|t| def_name(t).map(|n| missing_fn_names.contains(&n)).unwrap_or(false)) + .into_iter() + .filter(|t| impl_fns.iter().all(|i| def_name(i) != def_name(t))) .collect(); if missing_fns.is_empty() { return None; -- cgit v1.2.3