-
Notifications
You must be signed in to change notification settings - Fork 15.7k
Closed as duplicate of#32472
Closed as duplicate of#32472
Copy link
Labels
duplicateResolved as duplicateResolved as duplicatelibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Description
When using std::function I noticed that sometimes the captured data is copied even if the std::function is only ever moved.
I've tracked this down to the following code:
| __f_ = __as_base(&__buf_); |
It looks like when the small object optimization is in use for std::function, then the captured data is copied instead of moved whenever the function is moved. In extreme cases this could result in massively more work being done.
The issue reproduces trivially, see godbolt: https://godbolt.org/z/czTev8jfc
Note that the captured data needs to be < 3*sizeof(void *) and have noexcept on its copy constructor to trigger the small object optimization. When that's the case the data is copied instead of moved.
Metadata
Metadata
Assignees
Labels
duplicateResolved as duplicateResolved as duplicatelibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.