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: vec.extend(&vec![elem; len]) is slow, vec.resize() should be used instead #4660

Open
Shnatsel opened this issue Oct 12, 2019 · 1 comment
Labels
A-lint Area: New lints C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages L-perf Lint: Belongs in the perf lint group L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@Shnatsel
Copy link
Member

There are some very slow ways of extending a vector with len new elements:

vec.extend(&vec![elem; len]);
vec.extend_from_slice(&vec![elem; len]);

Instead it should be written like this:

vec.resize(vec.len() + len, elem);

This sounds like code that nobody would ever write, but it actually has real-world precedent: Frommi/miniz_oxide#55

@flip1995
Copy link
Member

This is kind of similar to #4078, which is currently being implemented in #4647.

@flip1995 flip1995 added L-perf Lint: Belongs in the perf lint group L-suggestion Lint: Improving, adding or fixing lint suggestions C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages A-lint Area: New lints labels Oct 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages L-perf Lint: Belongs in the perf lint group L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

No branches or pull requests

2 participants