[libcxx-commits] [libcxx] [libc++] Optimize ranges::copy for random_access_iterator inputs and vector<bool> iterator outputs (PR #120134)

Peng Liu via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jun 26 05:51:36 PDT 2025


================
@@ -50,6 +50,25 @@ constexpr auto wrap_input(std::vector<T>& input) {
   return std::ranges::subrange(std::move(b), std::move(e));
 }
 
+template <class Iter, class Sent>
+class random_access_range_wrapper {
----------------
winner245 wrote:

Thanks for catching this! It has now been fixed, and I've also rerun all the benchmarks. As we've introduced an extra `static_cast` to `bool` inside the inner loop for every bit, this has led to a nonnegligible cost. However, overall the optimization still brings a 3x performance improvement, as confirmed by my new benchmarks. Accordingly, I've updated the commit message a bit to reflect this. 

https://github.com/llvm/llvm-project/pull/120134


More information about the libcxx-commits mailing list