Skip to content

New lint: vec.extend(&vec![elem; len]) is slow, vec.resize() should be used instead #4660

Open
@Shnatsel

Description

@Shnatsel

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsC-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesL-perfLint: Belongs in the perf lint groupL-suggestionLint: Improving, adding or fixing lint suggestions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions