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

New lint: slow or unsafe vector initialization #3237

Closed
ishitatsuyuki opened this issue Sep 29, 2018 · 1 comment
Closed

New lint: slow or unsafe vector initialization #3237

ishitatsuyuki opened this issue Sep 29, 2018 · 1 comment
Labels
A-lint Area: New lints

Comments

@ishitatsuyuki
Copy link
Contributor

Cross post of rust-lang/rust#54628. See the thread for more details. The content below is a dumb summary.

Bad example

// resize
let mut vec1 = Vec::with_capacity(len);
vec1.resize(len, 0);
// extend
let mut vec2 = Vec::with_capacity(len);
vec2.extend(repeat(0).take(len))

Also some unsafe approaches exist, but it's TBD.

Good example

// vec! macro
let mut vec3 = vec![0; len];
@mcarton
Copy link
Member

mcarton commented Oct 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

No branches or pull requests

3 participants
@mcarton @ishitatsuyuki and others