Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

internal: optimize DepKindInfo -> DepKind conversion #15323

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 10 additions & 13 deletions crates/project-model/src/cargo_workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ pub struct PackageDependency {
pub kind: DepKind,
}

#[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Ord)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DepKind {
/// Available to the library, binary, and dev targets in the package (but not the build script).
Normal,
Expand All @@ -156,23 +156,20 @@ pub enum DepKind {
}

impl DepKind {
fn iter(list: &[cargo_metadata::DepKindInfo]) -> impl Iterator<Item = Self> + '_ {
let mut dep_kinds = Vec::new();
fn iter(list: &[cargo_metadata::DepKindInfo]) -> impl Iterator<Item = Self> {
let mut dep_kinds = [None; 3];
if list.is_empty() {
dep_kinds.push(Self::Normal);
dep_kinds[0] = Some(Self::Normal);
}
for info in list {
let kind = match info.kind {
cargo_metadata::DependencyKind::Normal => Self::Normal,
cargo_metadata::DependencyKind::Development => Self::Dev,
cargo_metadata::DependencyKind::Build => Self::Build,
match info.kind {
cargo_metadata::DependencyKind::Normal => dep_kinds[0] = Some(Self::Normal),
cargo_metadata::DependencyKind::Development => dep_kinds[1] = Some(Self::Dev),
cargo_metadata::DependencyKind::Build => dep_kinds[2] = Some(Self::Build),
cargo_metadata::DependencyKind::Unknown => continue,
};
dep_kinds.push(kind);
}
}
dep_kinds.sort_unstable();
dep_kinds.dedup();
dep_kinds.into_iter()
dep_kinds.into_iter().flatten()
}
}

Expand Down