Skip to content

Suggest resize rather when pushing same item to vec #4078

Closed
@pickfire

Description

@pickfire

Example in https://github.com/Gymmasssorla/finshir/blob/eae5d0c6761f5558c8ed33ef098d8bd13a07e64f/src/testing/helpers.rs#L55-L61

When pushing the same item to vec.

fn gen_portions() -> Vec<Vec<u8>> {
    let mut spaces = Vec::with_capacity(EMPTY_SPACES_COUNT);
    for _ in 0..EMPTY_SPACES_COUNT {
        spaces.push(vec![b' ']);
    }
    spaces
}

Could be.

fn gen_portions() -> Vec<Vec<u8>> {
    let mut spaces = Vec::with_capacity(EMPTY_SPACES_COUNT);
    spaces.resize(EMPTY_SPACES_COUNT, vec![b' ']);
    spaces
}

Maybe we could even use vec![b''].repeat(EMPTY_SPACES_COUNT) after stabilization ofrepeat_generic_size? rust-lang/rust#48784

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsL-complexityLint: Belongs in the complexity lint groupgood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions