# prefer-single-call

Combine consecutive Array.push or Array.unshift calls

Consecutive calls that append or prepend values to the same array repeat dispatch and capacity work.
Instead, you SHOULD pass all values to one `push` or `unshift` call.

Calls are combined only when the arguments cannot observe the intermediate array state.

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

## Reported

```ds title="main.ds"
function append(values: int32[]): void {
    values.push(1);
    values.push(2);
}
```

## Accepted

```ds title="main.ds"
function append(values: int32[]): void {
    values.push(1, 2);
}
```

## Prior art

- [eslint-plugin-unicorn · prefer-single-call](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-single-call.md)

[language/linter/src/rules/performance/prefer_single_call.rs:8](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/performance/prefer_single_call.rs#L8)
