-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Calculate the exact capacity for 2 HashMaps #52435
Conversation
r? @estebank (rust_highfive has picked a reviewer for you, use r? to override) |
src/librustc_driver/profile/trace.rs
Outdated
@@ -220,7 +220,8 @@ pub fn write_counts(count_file: &mut File, counts: &mut HashMap<String,QueryMetr | |||
} | |||
|
|||
pub fn write_traces(html_file: &mut File, counts_file: &mut File, traces: &Vec<Rec>) { | |||
let mut counts : HashMap<String,QueryMetric> = HashMap::new(); | |||
let capacity = traces.iter().fold(0, |acc, t| acc + 1 + t.extent.len()); | |||
let mut counts : HashMap<String,QueryMetric> = HashMap::with_capacity(capacity); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing comma between String
and QueryMetric
.
📌 Commit 20d7ffa7b9cec959c53dd67646068901766648e0 has been approved by |
No problem, done. |
@bors r=estebank |
📌 Commit d85bcef has been approved by |
@@ -51,7 +51,7 @@ pub fn build(build: &mut Build) { | |||
build_krate("", build, &mut resolves, "src/libtest"); | |||
build_krate(&build.rustc_features(), build, &mut resolves, "src/rustc"); | |||
|
|||
let mut id2name = HashMap::new(); | |||
let mut id2name = HashMap::with_capacity(build.crates.len()); | |||
for (name, krate) in build.crates.iter() { | |||
id2name.insert(krate.id.clone(), name.clone()); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For what it's worth, this one could also be done with map()
followed by collect()
.
Calculate the exact capacity for 2 HashMaps
Rollup of 9 pull requests Successful merges: - #52286 (Deny bare trait objects in src/librustc_errors) - #52306 (Reduce the number of clone()s needed in obligation_forest) - #52338 (update miri) - #52385 (Pass edition flags to compiler from rustdoc as expected) - #52392 (AsRef doc wording tweaks) - #52430 (update nomicon) - #52434 (Enable incremental independent of stage) - #52435 (Calculate the exact capacity for 2 HashMaps) - #52446 (Block beta if clippy breaks.) r? @ghost
No description provided.