https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101923

--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jonathan Wakely
<r...@gcc.gnu.org>:

https://gcc.gnu.org/g:73b0f810a17a5f529fc8342a2df31276d3538851

commit r11-9111-g73b0f810a17a5f529fc8342a2df31276d3538851
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Tue Aug 17 11:30:56 2021 +0100

    libstdc++: Optimize std::function move constructor [PR101923]

    PR 101923 points out that the unconditional swap in the std::function
    move constructor makes it slower than copying an empty std::function.
    The copy constructor has to check for the empty case before doing
    anything, and that makes it very fast for the empty case.

    Adding the same check to the move constructor avoids copying the
    _Any_data POD when we don't need to. We can also inline the effects of
    swap, by copying each member and then zeroing the pointer members.

    This makes moving an empty object at least as fast as copying an empty
    object.

    Signed-off-by: Jonathan Wakely <jwak...@redhat.com>

    libstdc++-v3/ChangeLog:

            PR libstdc++/101923
            * include/bits/std_function.h (function(function&&)): Check for
            non-empty parameter before doing any work.

    (cherry picked from commit 0808b0df9c4d31f4c362b9c85fb538b6aafcb517)

Reply via email to