Implicit conversion of concatenation result to immutable

Per Nordlöw per.nordlow at gmail.com
Thu Apr 1 22:23:55 UTC 2021


On Thursday, 1 April 2021 at 22:17:08 UTC, Per Nordlöw wrote:
> On Thursday, 1 April 2021 at 21:59:21 UTC, H. S. Teoh wrote:
>> Just use .idup on the result.
>
> That creates an unnecessary GC allocation in cases such
>
> ```d
> string x;
> const(char)[] y;
> throw new Exception(x ~ y.idup)
> ```

The alternative

```d
throw new Exception((x ~ y).idup)
```

, I now realized you referred to, is also unsound because `x ~ y` 
is already a unique freshly allocated unaliased slice that can be 
freely implicitly converted to `immutable`.


More information about the Digitalmars-d mailing list