Skip to content

Commit

Permalink
Remove some clones from pathfinding
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter554 committed Jan 11, 2025
1 parent 62d22e2 commit 7fcbd00
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/imports_info/queries/internal_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ pub struct InternalImportsPathQuery {
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
enum PathfindingNode {
enum PathfindingNode<'a> {
Initial,
PackageItem(PackageItemToken),
PackageItem(&'a PackageItemToken),
}

impl<'a> InternalImportsQueries<'a> {
Expand Down Expand Up @@ -415,15 +415,16 @@ impl<'a> InternalImportsQueries<'a> {

let reachable_items = bfs_reach(PathfindingNode::Initial, |item| {
let items = match item {
PathfindingNode::Initial => items.clone(),
PathfindingNode::PackageItem(item) => imports_map.get(item).unwrap().clone(),
PathfindingNode::Initial => &items,
PathfindingNode::PackageItem(item) => imports_map.get(item).unwrap(),
};
items.into_iter().map(PathfindingNode::PackageItem)
items.iter().map(PathfindingNode::PackageItem)
})
.filter_map(|item| match item {
PathfindingNode::Initial => None,
PathfindingNode::PackageItem(item) => Some(item),
})
.cloned()
.collect::<HashSet<_>>();

let reachable_items = &reachable_items - &items;
Expand Down Expand Up @@ -548,15 +549,12 @@ impl<'a> InternalImportsQueries<'a> {
&PathfindingNode::Initial,
|item| {
let items = match item {
PathfindingNode::Initial => query.from.clone(),
PathfindingNode::PackageItem(item) => self
.imports_info
.internal_imports
.get(item)
.unwrap()
.clone(),
PathfindingNode::Initial => &query.from,
PathfindingNode::PackageItem(item) => {
self.imports_info.internal_imports.get(item).unwrap()
}
};
let items = &items - &query.excluding_paths_via;
let items = items.difference(&query.excluding_paths_via);
items.into_iter().map(PathfindingNode::PackageItem)
},
|item| match item {
Expand All @@ -572,6 +570,7 @@ impl<'a> InternalImportsQueries<'a> {
PathfindingNode::PackageItem(item) => item,
PathfindingNode::Initial => panic!(),
})
.cloned()
.collect()
});

Expand Down

0 comments on commit 7fcbd00

Please sign in to comment.