[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
Fri Jul 3 08:23:22 PDT 2026
================
@@ -1120,14 +1122,26 @@ _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()) // construct the new trailing objects
+ std::uninitialized_fill_n(__old_last, (__from_e - __from_s) - __n, *__from_s);
----------------
ldionne wrote:
I'm not a huge fan of this, it seems pretty unclean. I'd rather take the slow code path when we're constant evaluating.
https://github.com/llvm/llvm-project/pull/207384
More information about the libcxx-commits
mailing list