Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: parallelize VisibilityTracker::from_crate (#424) #426

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/visibility_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ use std::collections::{HashMap, HashSet};

use rustdoc_types::{Crate, GenericArgs, Id, Item, ItemEnum, TypeAlias, Visibility};

#[cfg(feature = "rayon")]
use rayon::prelude::*;

use crate::{attributes::Attribute, ImportablePath};

#[derive(Debug, Clone)]
Expand All @@ -17,9 +20,14 @@ impl<'a> VisibilityTracker<'a> {
pub(crate) fn from_crate(crate_: &'a Crate) -> Self {
let mut visible_parent_ids = compute_parent_ids_for_public_items(crate_);

#[cfg(feature = "rayon")]
let iter = visible_parent_ids.par_iter_mut();
#[cfg(not(feature = "rayon"))]
let iter = visible_parent_ids.iter_mut();

// Sort and deduplicate parent ids.
// This ensures a consistent order, since queries can observe this order directly.
visible_parent_ids.iter_mut().for_each(|(_id, parent_ids)| {
iter.for_each(|(_id, parent_ids)| {
parent_ids.sort_unstable_by_key(|id| id.0.as_str());
parent_ids.dedup_by_key(|id| id.0.as_str());
});
Expand Down