Skip to content

Commit

Permalink
move to fxhashmap for speed, x2
Browse files Browse the repository at this point in the history
  • Loading branch information
klensy committed Dec 20, 2024
1 parent 81f8b7c commit 6edd9f1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
9 changes: 8 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ tempfile = "3.6"
toml = "0.8.6"
clap = { version = "4.1.4", features = ["derive"] }
strum = { version = "0.26.3", features = ["derive"] }
rustc-hash = "2.0"

[features]
debug = []
Expand Down
15 changes: 8 additions & 7 deletions src/cargo_ops/elaborate_workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use cargo::{
ops::{self, Packages},
util::{context::GlobalContext, interning::InternedString, CargoResult},
};
use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize};
use tabwriter::TabWriter;

Expand All @@ -31,10 +32,10 @@ use super::{pkg_status::*, Options};
/// the update status of packages
pub struct ElaborateWorkspace<'ela> {
pub workspace: &'ela Workspace<'ela>,
pub pkgs: HashMap<PackageId, Package>,
pub pkg_deps: HashMap<PackageId, HashMap<PackageId, Dependency>>,
pub pkgs: FxHashMap<PackageId, Package>,
pub pkg_deps: FxHashMap<PackageId, FxHashMap<PackageId, Dependency>>,
/// Map of package status
pub pkg_status: RefCell<HashMap<Vec<PackageId>, PkgStatus>>,
pub pkg_status: RefCell<FxHashMap<Vec<PackageId>, PkgStatus>>,
/// Whether using workspace mode
pub workspace_mode: bool,
}
Expand Down Expand Up @@ -103,13 +104,13 @@ impl<'ela> ElaborateWorkspace<'ela> {
let resolve = ws_resolve
.workspace_resolve
.expect("Error getting workspace resolved");
let mut pkgs = HashMap::new();
let mut pkg_deps = HashMap::new();
let mut pkgs = FxHashMap::default();
let mut pkg_deps = FxHashMap::default();
for pkg in packages.get_many(packages.package_ids())? {
let pkg_id = pkg.package_id();
pkgs.insert(pkg_id, pkg.clone());
let deps = pkg.dependencies();
let mut dep_map = HashMap::new();
let mut dep_map = FxHashMap::default();
for dep_id in resolve.deps(pkg_id) {
for d in deps {
if d.matches_id(dep_id.0) {
Expand All @@ -125,7 +126,7 @@ impl<'ela> ElaborateWorkspace<'ela> {
workspace,
pkgs,
pkg_deps,
pkg_status: RefCell::new(HashMap::new()),
pkg_status: RefCell::new(FxHashMap::default()),
workspace_mode: options.workspace || workspace.current().is_err(),
})
}
Expand Down

0 comments on commit 6edd9f1

Please sign in to comment.