diff options
author | Igor Matuszewski <[email protected]> | 2019-03-07 12:36:35 +0000 |
---|---|---|
committer | Igor Matuszewski <[email protected]> | 2019-03-16 21:41:13 +0000 |
commit | 406343492c9f1741fcc3eafbb13efa42691fe0db (patch) | |
tree | 35c39ba637ff82c1da154fe3c1ab2d3edafddc1b /crates | |
parent | 713975b1c1584bb141dfca84818bf5a7ca91a8ee (diff) |
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.
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_assists/src/add_missing_impl_members.rs | 11 |
1 files 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 @@ | |||
1 | use std::collections::HashSet; | ||
2 | |||
3 | use crate::{Assist, AssistId, AssistCtx}; | 1 | use crate::{Assist, AssistId, AssistCtx}; |
4 | 2 | ||
5 | use hir::Resolver; | 3 | use hir::Resolver; |
@@ -69,14 +67,9 @@ pub(crate) fn add_missing_impl_members(mut ctx: AssistCtx<impl HirDatabase>) -> | |||
69 | let trait_fns = trait_items.map(ImplItem::kind).filter_map(fn_def_opt).collect::<Vec<_>>(); | 67 | let trait_fns = trait_items.map(ImplItem::kind).filter_map(fn_def_opt).collect::<Vec<_>>(); |
70 | let impl_fns = impl_items.map(ImplItem::kind).filter_map(fn_def_opt).collect::<Vec<_>>(); | 68 | let impl_fns = impl_items.map(ImplItem::kind).filter_map(fn_def_opt).collect::<Vec<_>>(); |
71 | 69 | ||
72 | let trait_fn_names = trait_fns.iter().cloned().filter_map(def_name).collect::<HashSet<_>>(); | ||
73 | let impl_fn_names = impl_fns.iter().cloned().filter_map(def_name).collect::<HashSet<_>>(); | ||
74 | |||
75 | let missing_fn_names = trait_fn_names.difference(&impl_fn_names).collect::<HashSet<_>>(); | ||
76 | let missing_fns: Vec<_> = trait_fns | 70 | let missing_fns: Vec<_> = trait_fns |
77 | .iter() | 71 | .into_iter() |
78 | .cloned() | 72 | .filter(|t| impl_fns.iter().all(|i| def_name(i) != def_name(t))) |
79 | .filter(|t| def_name(t).map(|n| missing_fn_names.contains(&n)).unwrap_or(false)) | ||
80 | .collect(); | 73 | .collect(); |
81 | if missing_fns.is_empty() { | 74 | if missing_fns.is_empty() { |
82 | return None; | 75 | return None; |