Skip to content

Commit 86551eb

Browse files
authored
Merge pull request #44 from mclow/test-failures.2
Move the relocation code for insert/emplace into '__move_range'
2 parents 674792c + 57b0a81 commit 86551eb

File tree

1 file changed

+13
-45
lines changed

1 file changed

+13
-45
lines changed

libcxx/include/vector

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,6 +1625,19 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void
16251625
vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to) {
16261626
pointer __old_last = this->__end_;
16271627
difference_type __n = __old_last - __to;
1628+
1629+
#if _LIBCPP_STD_VER >= 26
1630+
if ! consteval {
1631+
if constexpr (is_trivially_relocatable_v<_Tp> || is_nothrow_move_constructible_v<_Tp>) {
1632+
const size_t __numSpaces = __to - __from_s;
1633+
_ConstructTransaction __tx(*this, __numSpaces);
1634+
(void) relocate(std::__to_address(__from_s), std::__to_address(__from_e), std::__to_address(__to));
1635+
__tx.__pos_ += __numSpaces;
1636+
return;
1637+
}
1638+
}
1639+
#endif
1640+
16281641
{
16291642
pointer __i = __from_s + __n;
16301643
_ConstructTransaction __tx(*this, __from_e - __i);
@@ -1643,23 +1656,6 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
16431656
if (__p == this->__end_) {
16441657
__construct_one_at_end(__x);
16451658
} else {
1646-
#if _LIBCPP_STD_VER >= 26
1647-
if constexpr (is_trivially_relocatable_v<_Tp> || is_nothrow_move_constructible_v<_Tp>) {
1648-
// Make space by trivially relocating everything
1649-
_ConstructTransaction __tx(*this, 1);
1650-
(void) relocate(std::__to_address(__p), std::__to_address(this->__end_), std::__to_address(__p + 1));
1651-
// construct the new element (not assign!)
1652-
const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1653-
if (std::__is_pointer_in_range(std::__to_address(__p), std::__to_address(__end_), std::addressof(__x)))
1654-
++__xr;
1655-
__alloc_traits::construct(this->__alloc(), std::__to_address(__p), *__xr);
1656-
++__tx.__pos_;
1657-
// Need to fix up upon an exception!
1658-
// update all the invariants.
1659-
// return an iterator to the new entry
1660-
return __make_iter(__p);
1661-
}
1662-
#endif
16631659
__move_range(__p, this->__end_, __p + 1);
16641660
const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
16651661
if (std::__is_pointer_in_range(std::__to_address(__p), std::__to_address(__end_), std::addressof(__x)))
@@ -1683,20 +1679,6 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x) {
16831679
if (__p == this->__end_) {
16841680
__construct_one_at_end(std::move(__x));
16851681
} else {
1686-
#if _LIBCPP_STD_VER >= 26
1687-
if constexpr (is_trivially_relocatable_v<_Tp> || is_nothrow_move_constructible_v<_Tp>) {
1688-
// Make space by trivially relocating everything
1689-
_ConstructTransaction __tx(*this, 1);
1690-
(void) relocate(std::__to_address(__p), std::__to_address(this->__end_), std::__to_address(__p + 1));
1691-
// construct the new element (not assign!)
1692-
__alloc_traits::construct(this->__alloc(), std::__to_address(__p), std::forward<value_type>(__x));
1693-
++__tx.__pos_;
1694-
// Need to fix up upon an exception!
1695-
// update all the invariants.
1696-
// return an iterator to the new entry
1697-
return __make_iter(__p);
1698-
}
1699-
#endif
17001682
__move_range(__p, this->__end_, __p + 1);
17011683
*__p = std::move(__x);
17021684
}
@@ -1718,20 +1700,6 @@ vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args) {
17181700
if (__p == this->__end_) {
17191701
__construct_one_at_end(std::forward<_Args>(__args)...);
17201702
} else {
1721-
#if _LIBCPP_STD_VER >= 26
1722-
if constexpr (is_trivially_relocatable_v<_Tp> || is_nothrow_move_constructible_v<_Tp>) {
1723-
// Make space by trivially relocating everything
1724-
_ConstructTransaction __tx(*this, 1);
1725-
(void) relocate(std::__to_address(__p), std::__to_address(this->__end_), std::__to_address(__p + 1));
1726-
// construct the new element
1727-
__alloc_traits::construct(this->__alloc(), std::__to_address(__p), std::forward<_Args>(__args)...);
1728-
++__tx.__pos_;
1729-
// Need to fix up upon an exception!
1730-
// update all the invariants.
1731-
// return an iterator to the new entry
1732-
return __make_iter(__p);
1733-
}
1734-
#endif
17351703
__temp_value<value_type, _Allocator> __tmp(this->__alloc(), std::forward<_Args>(__args)...);
17361704
__move_range(__p, this->__end_, __p + 1);
17371705
*__p = std::move(__tmp.get());

0 commit comments

Comments
 (0)