Skip to content

Commit 128a6a4

Browse files
Do not process indexed values more than once
1 parent 8f17f3d commit 128a6a4

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

crates/hir_def/src/import_map.rs

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -403,40 +403,42 @@ pub fn search_dependencies<'a>(
403403
}
404404

405405
let mut stream = op.union();
406-
let mut res = FxHashSet::default();
406+
407+
let mut all_indexed_values = FxHashSet::default();
407408
while let Some((_, indexed_values)) = stream.next() {
408-
for indexed_value in indexed_values {
409-
let import_map = &import_maps[indexed_value.index];
410-
let importables = &import_map.importables[indexed_value.value as usize..];
409+
all_indexed_values.extend(indexed_values.iter().copied());
410+
}
411411

412-
let common_importable_data = &import_map.map[&importables[0]];
413-
if !query.import_matches(common_importable_data, true) {
414-
continue;
415-
}
412+
let mut res = FxHashSet::default();
413+
for indexed_value in all_indexed_values {
414+
let import_map = &import_maps[indexed_value.index];
415+
let importables = &import_map.importables[indexed_value.value as usize..];
416416

417-
// Path shared by the importable items in this group.
418-
let common_importables_path_fst = fst_path(&common_importable_data.path);
419-
// Add the items from this `ModPath` group. Those are all subsequent items in
420-
// `importables` whose paths match `path`.
421-
let iter = importables
422-
.iter()
423-
.copied()
424-
.take_while(|item| {
425-
common_importables_path_fst == fst_path(&import_map.map[item].path)
426-
})
427-
.filter(|&item| match item_import_kind(item) {
428-
Some(import_kind) => !query.exclude_import_kinds.contains(&import_kind),
429-
None => true,
430-
})
431-
.filter(|item| {
432-
!query.case_sensitive // we've already checked the common importables path case-insensitively
417+
let common_importable_data = &import_map.map[&importables[0]];
418+
if !query.import_matches(common_importable_data, true) {
419+
continue;
420+
}
421+
422+
// Path shared by the importable items in this group.
423+
let common_importables_path_fst = fst_path(&common_importable_data.path);
424+
// Add the items from this `ModPath` group. Those are all subsequent items in
425+
// `importables` whose paths match `path`.
426+
let iter = importables
427+
.iter()
428+
.copied()
429+
.take_while(|item| common_importables_path_fst == fst_path(&import_map.map[item].path))
430+
.filter(|&item| match item_import_kind(item) {
431+
Some(import_kind) => !query.exclude_import_kinds.contains(&import_kind),
432+
None => true,
433+
})
434+
.filter(|item| {
435+
!query.case_sensitive // we've already checked the common importables path case-insensitively
433436
|| query.import_matches(&import_map.map[item], false)
434-
});
435-
res.extend(iter);
437+
});
438+
res.extend(iter);
436439

437-
if res.len() >= query.limit {
438-
return res;
439-
}
440+
if res.len() >= query.limit {
441+
return res;
440442
}
441443
}
442444

0 commit comments

Comments
 (0)