[Issue 5546] Assigning and initializing structs from functions make more copies than necessary

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Feb 8 00:44:43 PST 2011


http://d.puremagic.com/issues/show_bug.cgi?id=5546



--- Comment #2 from akb825 at gmail.com 2011-02-08 00:42:20 PST ---
After thinking about the problem a bit more, I have a couple things to add.

First, I should mention my second point for assigning the return value of a
function to an existing struct applies to all temporaries.

Test testVal;
testVal = Test("str");

can benefit from the same optimizations as

Test testVal;
testVal = function();

Second, it would be very useful to be able to mark the custom assignment
operator to have the same behavior on the above two cases as if there is no
overloaded assignment operator. (aka: skip the assignment and reduce it to a
blit + post blit and destruction of the old value when assigning from a
temporary) I would suggest something like putting "@ignoreIfTemp" before the
opAssign definition, and would be ignored if members of the struct have custom
assignment operators without that property. This would allow one of the most
useful benefits of rvalue references from C++0x to be used without having to
add a whole new type qualifier.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list