# same-item-push

Prefer bulk initialization over repeatedly pushing one invariant value

A counted loop that only pushes one invariant value repeatedly grows and initializes a collection element by element.
Instead, you SHOULD use bulk repeated initialization or resize the collection once.

- Category: performance
- Level: warning
- Fix: none
- Scope: module

## Reported

```ds title="main.ds"
function append(values: int32[], count: isize): void {
    for (const _ of 0..count) {
        values.push(0);
    }
}
```

## Accepted

```ds title="main.ds"
function append(values: int32[], count: isize): void {
    if (count > 0) {
        values.resize(values.length + count, 0);
    }
}
```

## Prior art

- [Clippy · same_item_push](https://rust-lang.github.io/rust-clippy/master/index.html#same_item_push)

[language/linter/src/rules/performance/same_item_push.rs:6](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/performance/same_item_push.rs#L6)
