use std::path::{Path, PathBuf};
use rustc_hash::{FxHashMap, FxHashSet};
use super::{CategorizedEntryPoints, dedup_entry_paths};
impl CategorizedEntryPoints {
#[must_use]
pub(crate) fn dedup(mut self) -> Self {
self.retain_fixture_only_paths();
dedup_entry_paths(&mut self.all);
dedup_entry_paths(&mut self.runtime);
dedup_entry_paths(&mut self.test);
dedup_entry_paths(&mut self.support);
if !self.production_excluded.is_empty() {
let seeded: FxHashSet<&Path> = self.all.iter().map(|ep| ep.path.as_path()).collect();
self.production_excluded
.retain(|path| !seeded.contains(path.as_path()));
self.production_excluded.sort_unstable();
self.production_excluded.dedup();
}
self
}
fn retain_fixture_only_paths(&mut self) {
if self.fixture_only.is_empty() {
return;
}
let mut fixture_counts: FxHashMap<&Path, usize> = FxHashMap::default();
for path in &self.fixture_only {
*fixture_counts.entry(path.as_path()).or_default() += 1;
}
let mut entry_counts: FxHashMap<&Path, usize> = FxHashMap::default();
for entry in &self.all {
if fixture_counts.contains_key(entry.path.as_path()) {
*entry_counts.entry(entry.path.as_path()).or_default() += 1;
}
}
let kept: FxHashSet<PathBuf> = fixture_counts
.iter()
.filter(|(path, count)| entry_counts.get(*path) == Some(count))
.map(|(path, _)| path.to_path_buf())
.collect();
self.fixture_only.retain(|path| kept.contains(path));
self.fixture_only.sort_unstable();
self.fixture_only.dedup();
}
#[must_use]
pub(crate) fn fixture_only(&self) -> &[PathBuf] {
&self.fixture_only
}
}