-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[slow_vector_initialization
]: clarify why Vec::new()
+ resize is worse
#11310
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
Conversation
r? @xFrednet (rustbot has picked a reviewer for you, use r? to override) |
It makes it clear that advantage is because of zero value. I though that zero values matter for Is the lint inhibited for |
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.
This is great, thanks!
Co-authored-by: Dirkjan Ochtman <[email protected]>
It only lints if the value argument in |
Yup, looks great to me! |
I forgot the @bors r=xFrednet,djc |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
#11198 extended this lint to also warn on
Vec::new()
+resize(0, len)
, but did not update the lint documentation, so it left some confused (#10938 (comment)).This PR should make it a bit more clear. (cc @djc @vi what do you think about this?)
More details
Godbolt for
Vec::new()
+.resize(x, 0)
: https://godbolt.org/z/e7q9xc9rGThe resize call first does a normal allocation (
__rust_alloc
):Then a memset for zero initialization:
Godbolt for
vec![0; len]
: https://godbolt.org/z/M3vr53vWYImportant bit:
changelog: [
slow_vector_initialization
]: clarify whyVec::new()
+ resize is worse thanvec![0; len]