Performance tweaking rotate.
rotate is a critical algorithm because it is often used by other algorithms, both std and non-std. The main thrust of this optimization is a specialized algorithm when the 'distance' to be shifted is 1 (either left or right). To my surprise, this 'optimization' was not effective for types like std::string. std::string favors rotate algorithms which only use swap. But for types like scalars, and especially when the sequence is random access, these new specializations are a big win. If it is a vector<size_t> for example, the rotate is done via a memmove and can be several times faster than the gcd algorithm. I'm using is_trivially_move_assignable to distinguish between types like int and types like string. This is obviously an ad-hoc approximation, but I haven't found a case where it doesn't give good results. I've used a 'static if' (with is_trivially_move_assignable) in three places. Testing with both -Os and -O3 showed that clang eliminated all code not be executed by the 'static if' (including the 'static if' itself). llvm-svn: 161247
Loading
Please register or sign in to comment