[LLVMbugs] [Bug 12105] New: libc++ std::function is relatively inefficient in terms of copying

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Feb 27 17:38:54 PST 2012


http://llvm.org/bugs/show_bug.cgi?id=12105

             Bug #: 12105
           Summary: libc++ std::function is relatively inefficient in
                    terms of copying
           Product: libc++
           Version: unspecified
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: All Bugs
        AssignedTo: hhinnant at apple.com
        ReportedBy: sharparrow1 at yahoo.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


See
http://stackoverflow.com/questions/8203211/how-can-i-make-the-storage-of-c-lambda-objects-more-efficient
.  An complete testcase:

#include <cstdio>
#include <functional>
class Simple {
public:
    Simple( int value ) { puts( "Constructing simple!" ); this->value = value;
}
    Simple( const Simple& rhs ) { puts( "Copying simple!" ); this->value =
rhs.value; }
    Simple( Simple&& rhs ) { puts( "Moving simple!" ); this->value = rhs.value;
}
    ~Simple() { puts( "Destroying simple!" ); }
    int Get() const { return this->value; }

private:
    int value;
};
int main()
{
    Simple test( 5 );

    std::function<int ()> f =
        [test] ()
        {
            return test.Get();
        };

    printf( "%d\n", f() );
}


With libc++, the result is currently:

Constructing simple!
Copying simple!
Moving simple!
Moving simple!
Moving simple!
Moving simple!
Destroying simple!
Destroying simple!
Destroying simple!
Destroying simple!
5
Destroying simple!
Destroying simple!

Three unnecessary calls to the lambda's move constructor is relatively bad.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list