Re:Effortless Performance Improvements in C++: std:vector
by jeffbee on Thursday March 09, 2023 @09:36AM
(#35081574)
I don’t see why moving std::string needs to branch. You just copy the source and then zero it out, unconditionally.
[ Parent
| on HN ]
Re:Effortless Performance Improvements in C++: std:vector
by ckennelly on Thursday March 09, 2023 @11:44PM
(#35090479)
It depends on your STL implementation's representation of string: https://godbolt.org/z/nMYGYoWbq
* libstdc++ has an internal reference to its own address for the SSO. If the moved-from string was referencing its SSO buffer, the moved-to string needs to use its own address. The branch is differentiating the SSO state from a heap-allocated state.
* libc++ string move can be implemented this way, but the branch ends up happening on access to the string. It still needs to discard the old heap allocated buffer, if need-be as well.