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

fix clippy slow_vector_initialization #618

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions src/dbghelp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#![allow(non_snake_case)]

use alloc::vec;
use alloc::vec::Vec;

use super::windows::*;
Expand Down Expand Up @@ -409,8 +410,7 @@ pub fn init() -> Result<Init, ()> {
//
// See https://learn.microsoft.com/cpp/build/reference/pdbpath for an
// example of where symbols are usually searched for.
let mut search_path_buf = Vec::new();
search_path_buf.resize(1024, 0);
let mut search_path_buf = vec![0; 1024];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. This could be with_capacity, and then we pass the search_path_buf.capacity() when indicating how much space we have to allocate, and then we pass a search_path_buf.set_len after filling it.

...or that could be over-optimization as we are likely to get a fresh raw page from the OS because this was a calloc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fresh pages from the OS may still be more expensive than a recycled allocation from a pooling allocator. But I'd only play those kinds of games if this shows up in a benchmark and not just clippy linting about it.


// Prefill the buffer with the current search path.
if DBGHELP.SymGetSearchPathW().unwrap()(
Expand Down
Loading