[libcxx-commits] [libcxx] [libc++] Optimize vector::__move_range for trivially copyable types (PR #207384)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Aug 5 08:00:03 PDT 2026


================
@@ -1118,6 +1120,18 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void
 vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to) {
   pointer __old_last  = __layout_.__end_ptr();
   difference_type __n = __old_last - __to;
+#ifndef _LIBCPP_CXX03_LANG
+  if constexpr (__allocator_has_trivial_move_construct_v<allocator_type, value_type> &&
+                is_trivially_copyable<value_type>::value) {
+    if (!__libcpp_is_constant_evaluated()) {
+      auto __count = __from_e - __from_s;
+      __annotate_increase(__count - __n);
+      std::__constexpr_memmove(std::__to_address(__to), std::__to_address(__from_s), __element_count(__count));
----------------
ldionne wrote:

If we try rewriting this memmove as a loop, what do the benchmarks look like?

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


More information about the libcxx-commits mailing list