pop & popFront combined

via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Nov 2 05:35:27 PST 2014


On Sunday, 2 November 2014 at 12:29:14 UTC, Nordlöw wrote:
> On Sunday, 2 November 2014 at 11:46:19 UTC, Marc Schütz wrote:
>> I think DMD doesn't generate good code for it; IIRC it lowers 
>> scope(success) to a strange construct with an invisible 
>> variable and a try/catch. Don't know the reasons for this, 
>> maybe it has changed by now. Theoretically it would just need 
>> to move the contents of the scope(success) after the 
>> evaluation of the returned expression, which is cheap.
>
> Are there cases in LDC where
>
>     auto e = r.moveFront;
>     r.popFront;
>     return e;
>
> generates code less efficient than
>
>     scope(success) r.popFront;
>     return r.moveFront;
>
> because of the extra assignment?

I'm not sure. If the element type has a postblit, there might be 
some obscure corner case where the language specification 
requires a copy if you declare a named variable. In general I 
would expect no (language level) copy to take place. The result 
of `moveFront` can just be moved into the yet uninitialized `e`, 
which later can be moved up to the caller. These are simple 
bitblits, not copies.


More information about the Digitalmars-d-learn mailing list