diff options
author | Kirill Bulatov <[email protected]> | 2021-03-08 10:06:15 +0000 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2021-03-08 10:06:15 +0000 |
commit | 128a6a4ec060a73fbd4e1a8dc470cb629fcdbe45 (patch) | |
tree | e224ca980df52f8aae6796fc9d7f316cdce6c421 /crates/hir_def | |
parent | 8f17f3d594f599b5f1a9c9960d363513368e0958 (diff) |
Do not process indexed values more than once
Diffstat (limited to 'crates/hir_def')
-rw-r--r-- | crates/hir_def/src/import_map.rs | 60 |
1 files changed, 31 insertions, 29 deletions
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>( | |||
403 | } | 403 | } |
404 | 404 | ||
405 | let mut stream = op.union(); | 405 | let mut stream = op.union(); |
406 | let mut res = FxHashSet::default(); | 406 | |
407 | let mut all_indexed_values = FxHashSet::default(); | ||
407 | while let Some((_, indexed_values)) = stream.next() { | 408 | while let Some((_, indexed_values)) = stream.next() { |
408 | for indexed_value in indexed_values { | 409 | all_indexed_values.extend(indexed_values.iter().copied()); |
409 | let import_map = &import_maps[indexed_value.index]; | 410 | } |
410 | let importables = &import_map.importables[indexed_value.value as usize..]; | ||
411 | 411 | ||
412 | let common_importable_data = &import_map.map[&importables[0]]; | 412 | let mut res = FxHashSet::default(); |
413 | if !query.import_matches(common_importable_data, true) { | 413 | for indexed_value in all_indexed_values { |
414 | continue; | 414 | let import_map = &import_maps[indexed_value.index]; |
415 | } | 415 | let importables = &import_map.importables[indexed_value.value as usize..]; |
416 | 416 | ||
417 | // Path shared by the importable items in this group. | 417 | let common_importable_data = &import_map.map[&importables[0]]; |
418 | let common_importables_path_fst = fst_path(&common_importable_data.path); | 418 | if !query.import_matches(common_importable_data, true) { |
419 | // Add the items from this `ModPath` group. Those are all subsequent items in | 419 | continue; |
420 | // `importables` whose paths match `path`. | 420 | } |
421 | let iter = importables | 421 | |
422 | .iter() | 422 | // Path shared by the importable items in this group. |
423 | .copied() | 423 | let common_importables_path_fst = fst_path(&common_importable_data.path); |
424 | .take_while(|item| { | 424 | // Add the items from this `ModPath` group. Those are all subsequent items in |
425 | common_importables_path_fst == fst_path(&import_map.map[item].path) | 425 | // `importables` whose paths match `path`. |
426 | }) | 426 | let iter = importables |
427 | .filter(|&item| match item_import_kind(item) { | 427 | .iter() |
428 | Some(import_kind) => !query.exclude_import_kinds.contains(&import_kind), | 428 | .copied() |
429 | None => true, | 429 | .take_while(|item| common_importables_path_fst == fst_path(&import_map.map[item].path)) |
430 | }) | 430 | .filter(|&item| match item_import_kind(item) { |
431 | .filter(|item| { | 431 | Some(import_kind) => !query.exclude_import_kinds.contains(&import_kind), |
432 | !query.case_sensitive // we've already checked the common importables path case-insensitively | 432 | None => true, |
433 | }) | ||
434 | .filter(|item| { | ||
435 | !query.case_sensitive // we've already checked the common importables path case-insensitively | ||
433 | || query.import_matches(&import_map.map[item], false) | 436 | || query.import_matches(&import_map.map[item], false) |
434 | }); | 437 | }); |
435 | res.extend(iter); | 438 | res.extend(iter); |
436 | 439 | ||
437 | if res.len() >= query.limit { | 440 | if res.len() >= query.limit { |
438 | return res; | 441 | return res; |
439 | } | ||
440 | } | 442 | } |
441 | } | 443 | } |
442 | 444 | ||