Optimize small_vector copy and move for inline storage
Summary: Codegen for copy and move assignment is suboptimal when the vectors involved are inline, in particular if the destination is default-constructed (which is very common) and even more so if the value type is trivially copyable. The main optimization is that if the storage is inline and the type is trivially-copyable, we can just copy the whole storage, regardless of the size of the container. This avoids a branchy loop, and it's usually just a handful of MOVs. While at it, optimized all the related code paths by avoiding delegating to `swap()` and `assign()` when possible, which introduce further branches that are hard to optimize. Also move and copy in place when the vector is non-empty, avoiding unnecessary destructions. Also fixed a couple of bugs: - The move constructor did not clear its argument when inline, inconsistently with the move assignment and `std::vector` - The move assignment operator passed its heap storage to the argument instead of freeing it. Reviewed By: yfeldblum Differential Revision: D29592519 fbshipit-source-id: 6281cdda775568d28619afea8b7ca2fb168c7e5d
Showing
Please register or sign in to comment