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.