www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - std.algorithm.swap and memcpy

reply dsimcha <dsimcha yahoo.com> writes:
I saw in the changelog that std.algorithm.swap now uses memcpy because it's
faster than the old way.  Why is this?  If memcpy is faster, how come DMD
doesn't generate the same instructions for normal assignment?
Jul 06 2009
parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
dsimcha wrote:
 I saw in the changelog that std.algorithm.swap now uses memcpy because it's
 faster than the old way.  Why is this?  If memcpy is faster, how come DMD
 doesn't generate the same instructions for normal assignment?

The problem was that the copy construction and assignment were previously used. Those could be intercepted and made arbitrarily costly. Andrei
Jul 06 2009