# repeated-string-growth

Disallow repeatedly rebuilding a growing string in an iteration

Concatenating into storage that survives an iteration repeatedly copies the text accumulated so far.
Instead, you SHOULD append into a `StringBuilder` and convert it into a string after the iteration.

Counted loops that append one invariant string can append a single `repeat` result.

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

## Reported

```ds title="main.ds"
function indent(depth: isize): string {
    let output = "";
    for (const _ of 0..depth) {
        output += "  ";
    }

    return output;
}
```

## Accepted

```ds title="main.ds"
function indent(depth: isize): string {
    let output = "";
    output += "  ".repeat(depth > 0 ? depth : 0);

    return output;
}
```

[language/linter/src/rules/performance/repeated_string_growth.rs:9](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/performance/repeated_string_growth.rs#L9)
