Modify

Opened 9 years ago

Last modified 5 years ago

#2319 new Bugs

function::operator= should "move", copy assignment should have by-value argument

Reported by: Niels Dekker Owned by: Douglas Gregor
Milestone: Boost 1.37.0 Component: function
Version: Boost 1.36.0 Severity: Optimization
Keywords: Cc: Niels Dekker

Description

A few days ago, I added a comment to ticket #1910 (regarding function::swap), suggesting to have boost::function's assignment operators calling its new move_assign member function, instead of calling swap. Doing so would significantly improve its performance.

Now I think that function::operator= deserves its own ticket, especially because the copy assignment of boost::function can be improved even more, by having its argument passed by value, instead of creating a copy of the argument inside the body of the function. Doing so would allow the compiler to do copy elision, when its argument is an rvalue. See also Improving the assignment operators of various Boost types

So please consider the attached patch.

Attachments (1)

function_assignment.patch (1.1 KB) - added by Niels Dekker 9 years ago.

Download all attachments as: .zip

Change History (3)

Changed 9 years ago by Niels Dekker

Attachment: function_assignment.patch added

comment:1 Changed 9 years ago by Niels Dekker

Severity: ProblemOptimization

comment:2 Changed 5 years ago by Antony Polukhin

Your patch adds memory leaks for cases, when function is already initialized with big functional object (move_assign member function does not call clean()).

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The owner will remain Douglas Gregor.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.