# no-allocation-for-comparison

Disallow allocating conversions performed only to compare

Converting a borrowed string or path into owned storage solely for equality performs an allocation without changing the comparison.
Instead, you SHOULD compare the borrowed and owned representations directly.

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

## Reported

```ds title="main.ds"
import { StringSlice } from "destack:string";

function matches(value: &readonly StringSlice, expected: string): boolean {
    return value.toOwned() == expected;
}
```

## Accepted

```ds title="main.ds"
import { StringSlice } from "destack:string";

function matches(value: &readonly StringSlice, expected: string): boolean {
    return value == expected;
}
```

## Prior art

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

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