Idea for avoiding GC for lambdas

rm rymrg at memail.com
Tue Jun 22 06:20:59 UTC 2021


On 21/06/2021 23:01, Steven Schveighoffer wrote:
> I have some code in my codebase that does stuff like this:
> 
> ```d
> struct S
> {
>     int id;
>     int field1;
> }
> 
> auto foo(S[] arr, int someval) // @nogc not allowed :(
> {
>     // remove all the elements of arr that have someval for field1
>     import std.algorithm;
>     return arr.filter!(v => v.field1 == someval);
> }
> ```
> 
> While this works, and is nice, it's using a lambda with local references 
> to filter data. This means a GC closure allocation is involved.
> 
 > *snip*

It does come up every so often. You can also follow the links here.
https://forum.dlang.org/post/qnigarkuxxnqwdernhzv@forum.dlang.org


Maybe the zip+repeat trick should be streamlined a bit.


More information about the Digitalmars-d mailing list