From 128a6a4ec060a73fbd4e1a8dc470cb629fcdbe45 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 8 Mar 2021 12:06:15 +0200 Subject: Do not process indexed values more than once --- crates/hir_def/src/import_map.rs | 60 +++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 29 deletions(-) (limited to 'crates/hir_def') diff --git a/crates/hir_def/src/import_map.rs b/crates/hir_def/src/import_map.rs index 420619116..e1c28bc83 100644 --- a/crates/hir_def/src/import_map.rs +++ b/crates/hir_def/src/import_map.rs @@ -403,40 +403,42 @@ pub fn search_dependencies<'a>( } let mut stream = op.union(); - let mut res = FxHashSet::default(); + + let mut all_indexed_values = FxHashSet::default(); while let Some((_, indexed_values)) = stream.next() { - for indexed_value in indexed_values { - let import_map = &import_maps[indexed_value.index]; - let importables = &import_map.importables[indexed_value.value as usize..]; + all_indexed_values.extend(indexed_values.iter().copied()); + } - let common_importable_data = &import_map.map[&importables[0]]; - if !query.import_matches(common_importable_data, true) { - continue; - } + let mut res = FxHashSet::default(); + for indexed_value in all_indexed_values { + let import_map = &import_maps[indexed_value.index]; + let importables = &import_map.importables[indexed_value.value as usize..]; - // Path shared by the importable items in this group. - let common_importables_path_fst = fst_path(&common_importable_data.path); - // Add the items from this `ModPath` group. Those are all subsequent items in - // `importables` whose paths match `path`. - let iter = importables - .iter() - .copied() - .take_while(|item| { - common_importables_path_fst == fst_path(&import_map.map[item].path) - }) - .filter(|&item| match item_import_kind(item) { - Some(import_kind) => !query.exclude_import_kinds.contains(&import_kind), - None => true, - }) - .filter(|item| { - !query.case_sensitive // we've already checked the common importables path case-insensitively + let common_importable_data = &import_map.map[&importables[0]]; + if !query.import_matches(common_importable_data, true) { + continue; + } + + // Path shared by the importable items in this group. + let common_importables_path_fst = fst_path(&common_importable_data.path); + // Add the items from this `ModPath` group. Those are all subsequent items in + // `importables` whose paths match `path`. + let iter = importables + .iter() + .copied() + .take_while(|item| common_importables_path_fst == fst_path(&import_map.map[item].path)) + .filter(|&item| match item_import_kind(item) { + Some(import_kind) => !query.exclude_import_kinds.contains(&import_kind), + None => true, + }) + .filter(|item| { + !query.case_sensitive // we've already checked the common importables path case-insensitively || query.import_matches(&import_map.map[item], false) - }); - res.extend(iter); + }); + res.extend(iter); - if res.len() >= query.limit { - return res; - } + if res.len() >= query.limit { + return res; } } -- cgit v1.2.3