Skip to content

Commit 32d7002

Browse files
committed
[libc++] Remove initializer_list specific optimization in __tree
1 parent 89206de commit 32d7002

File tree

3 files changed

+8
-162
lines changed

3 files changed

+8
-162
lines changed

libcxx/include/__tree

Lines changed: 0 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -902,8 +902,6 @@ public:
902902
_LIBCPP_HIDE_FROM_ABI __tree& operator=(const __tree& __t);
903903
template <class _ForwardIterator>
904904
_LIBCPP_HIDE_FROM_ABI void __assign_unique(_ForwardIterator __first, _ForwardIterator __last);
905-
template <class _InputIterator>
906-
_LIBCPP_HIDE_FROM_ABI void __assign_multi(_InputIterator __first, _InputIterator __last);
907905
_LIBCPP_HIDE_FROM_ABI __tree(__tree&& __t) _NOEXCEPT_(
908906
is_nothrow_move_constructible<__node_allocator>::value&& is_nothrow_move_constructible<value_compare>::value);
909907
_LIBCPP_HIDE_FROM_ABI __tree(__tree&& __t, const allocator_type& __a);
@@ -1036,11 +1034,6 @@ public:
10361034
}
10371035
}
10381036

1039-
_LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __node_assign_unique(const value_type& __v, __node_pointer __dest);
1040-
1041-
_LIBCPP_HIDE_FROM_ABI iterator __node_insert_multi(__node_pointer __nd);
1042-
_LIBCPP_HIDE_FROM_ABI iterator __node_insert_multi(const_iterator __p, __node_pointer __nd);
1043-
10441037
template <class _InIter, class _Sent>
10451038
_LIBCPP_HIDE_FROM_ABI void __insert_range_unique(_InIter __first, _Sent __last) {
10461039
if (__first == __last)
@@ -1311,43 +1304,6 @@ private:
13111304
__lhs = std::forward<_From>(__rhs);
13121305
}
13131306

1314-
struct _DetachedTreeCache {
1315-
_LIBCPP_HIDE_FROM_ABI explicit _DetachedTreeCache(__tree* __t) _NOEXCEPT
1316-
: __t_(__t),
1317-
__cache_root_(__detach_from_tree(__t)) {
1318-
__advance();
1319-
}
1320-
1321-
_LIBCPP_HIDE_FROM_ABI __node_pointer __get() const _NOEXCEPT { return __cache_elem_; }
1322-
1323-
_LIBCPP_HIDE_FROM_ABI void __advance() _NOEXCEPT {
1324-
__cache_elem_ = __cache_root_;
1325-
if (__cache_root_) {
1326-
__cache_root_ = __detach_next(__cache_root_);
1327-
}
1328-
}
1329-
1330-
_LIBCPP_HIDE_FROM_ABI ~_DetachedTreeCache() {
1331-
__t_->destroy(__cache_elem_);
1332-
if (__cache_root_) {
1333-
while (__cache_root_->__parent_ != nullptr)
1334-
__cache_root_ = static_cast<__node_pointer>(__cache_root_->__parent_);
1335-
__t_->destroy(__cache_root_);
1336-
}
1337-
}
1338-
1339-
_DetachedTreeCache(_DetachedTreeCache const&) = delete;
1340-
_DetachedTreeCache& operator=(_DetachedTreeCache const&) = delete;
1341-
1342-
private:
1343-
_LIBCPP_HIDE_FROM_ABI static __node_pointer __detach_from_tree(__tree* __t) _NOEXCEPT;
1344-
_LIBCPP_HIDE_FROM_ABI static __node_pointer __detach_next(__node_pointer) _NOEXCEPT;
1345-
1346-
__tree* __t_;
1347-
__node_pointer __cache_root_;
1348-
__node_pointer __cache_elem_;
1349-
};
1350-
13511307
class __tree_deleter {
13521308
__node_allocator& __alloc_;
13531309

@@ -1486,47 +1442,6 @@ private:
14861442
}
14871443
};
14881444

1489-
// Precondition: __size_ != 0
1490-
template <class _Tp, class _Compare, class _Allocator>
1491-
typename __tree<_Tp, _Compare, _Allocator>::__node_pointer
1492-
__tree<_Tp, _Compare, _Allocator>::_DetachedTreeCache::__detach_from_tree(__tree* __t) _NOEXCEPT {
1493-
__node_pointer __cache = static_cast<__node_pointer>(__t->__begin_node_);
1494-
__t->__begin_node_ = __t->__end_node();
1495-
__t->__end_node()->__left_->__parent_ = nullptr;
1496-
__t->__end_node()->__left_ = nullptr;
1497-
__t->__size_ = 0;
1498-
// __cache->__left_ == nullptr
1499-
if (__cache->__right_ != nullptr)
1500-
__cache = static_cast<__node_pointer>(__cache->__right_);
1501-
// __cache->__left_ == nullptr
1502-
// __cache->__right_ == nullptr
1503-
return __cache;
1504-
}
1505-
1506-
// Precondition: __cache != nullptr
1507-
// __cache->left_ == nullptr
1508-
// __cache->right_ == nullptr
1509-
// This is no longer a red-black tree
1510-
template <class _Tp, class _Compare, class _Allocator>
1511-
typename __tree<_Tp, _Compare, _Allocator>::__node_pointer
1512-
__tree<_Tp, _Compare, _Allocator>::_DetachedTreeCache::__detach_next(__node_pointer __cache) _NOEXCEPT {
1513-
if (__cache->__parent_ == nullptr)
1514-
return nullptr;
1515-
if (std::__tree_is_left_child(static_cast<__node_base_pointer>(__cache))) {
1516-
__cache->__parent_->__left_ = nullptr;
1517-
__cache = static_cast<__node_pointer>(__cache->__parent_);
1518-
if (__cache->__right_ == nullptr)
1519-
return __cache;
1520-
return static_cast<__node_pointer>(std::__tree_leaf(__cache->__right_));
1521-
}
1522-
// __cache is right child
1523-
__cache->__parent_unsafe()->__right_ = nullptr;
1524-
__cache = static_cast<__node_pointer>(__cache->__parent_);
1525-
if (__cache->__left_ == nullptr)
1526-
return __cache;
1527-
return static_cast<__node_pointer>(std::__tree_leaf(__cache->__left_));
1528-
}
1529-
15301445
template <class _Tp, class _Compare, class _Allocator>
15311446
__tree<_Tp, _Compare, _Allocator>& __tree<_Tp, _Compare, _Allocator>::operator=(const __tree& __t) {
15321447
if (this == std::addressof(__t))
@@ -1549,46 +1464,6 @@ __tree<_Tp, _Compare, _Allocator>& __tree<_Tp, _Compare, _Allocator>::operator=(
15491464
return *this;
15501465
}
15511466

1552-
template <class _Tp, class _Compare, class _Allocator>
1553-
template <class _ForwardIterator>
1554-
void __tree<_Tp, _Compare, _Allocator>::__assign_unique(_ForwardIterator __first, _ForwardIterator __last) {
1555-
using _ITraits = iterator_traits<_ForwardIterator>;
1556-
using _ItValueType = typename _ITraits::value_type;
1557-
static_assert(
1558-
is_same<_ItValueType, value_type>::value, "__assign_unique may only be called with the containers value type");
1559-
static_assert(
1560-
__has_forward_iterator_category<_ForwardIterator>::value, "__assign_unique requires a forward iterator");
1561-
if (__size_ != 0) {
1562-
_DetachedTreeCache __cache(this);
1563-
for (; __cache.__get() != nullptr && __first != __last; ++__first) {
1564-
if (__node_assign_unique(*__first, __cache.__get()).second)
1565-
__cache.__advance();
1566-
}
1567-
}
1568-
for (; __first != __last; ++__first)
1569-
__emplace_unique(*__first);
1570-
}
1571-
1572-
template <class _Tp, class _Compare, class _Allocator>
1573-
template <class _InputIterator>
1574-
void __tree<_Tp, _Compare, _Allocator>::__assign_multi(_InputIterator __first, _InputIterator __last) {
1575-
using _ITraits = iterator_traits<_InputIterator>;
1576-
using _ItValueType = typename _ITraits::value_type;
1577-
static_assert(
1578-
is_same<_ItValueType, value_type>::value, "__assign_multi may only be called with the containers value_type");
1579-
if (__size_ != 0) {
1580-
_DetachedTreeCache __cache(this);
1581-
for (; __cache.__get() && __first != __last; ++__first) {
1582-
__assign_value(__cache.__get()->__get_value(), *__first);
1583-
__node_insert_multi(__cache.__get());
1584-
__cache.__advance();
1585-
}
1586-
}
1587-
const_iterator __e = end();
1588-
for (; __first != __last; ++__first)
1589-
__emplace_hint_multi(__e, *__first);
1590-
}
1591-
15921467
template <class _Tp, class _Compare, class _Allocator>
15931468
__tree<_Tp, _Compare, _Allocator>::__tree(const __tree& __t)
15941469
: __begin_node_(__end_node()),
@@ -1942,39 +1817,6 @@ __tree<_Tp, _Compare, _Allocator>::__emplace_hint_multi(const_iterator __p, _Arg
19421817
return iterator(static_cast<__node_pointer>(__h.release()));
19431818
}
19441819

1945-
template <class _Tp, class _Compare, class _Allocator>
1946-
pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, bool>
1947-
__tree<_Tp, _Compare, _Allocator>::__node_assign_unique(const value_type& __v, __node_pointer __nd) {
1948-
auto [__parent, __child] = __find_equal(__v);
1949-
__node_pointer __r = static_cast<__node_pointer>(__child);
1950-
bool __inserted = false;
1951-
if (__child == nullptr) {
1952-
__assign_value(__nd->__get_value(), __v);
1953-
__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd));
1954-
__r = __nd;
1955-
__inserted = true;
1956-
}
1957-
return pair<iterator, bool>(iterator(__r), __inserted);
1958-
}
1959-
1960-
template <class _Tp, class _Compare, class _Allocator>
1961-
typename __tree<_Tp, _Compare, _Allocator>::iterator
1962-
__tree<_Tp, _Compare, _Allocator>::__node_insert_multi(__node_pointer __nd) {
1963-
__end_node_pointer __parent;
1964-
__node_base_pointer& __child = __find_leaf_high(__parent, __nd->__get_value());
1965-
__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd));
1966-
return iterator(__nd);
1967-
}
1968-
1969-
template <class _Tp, class _Compare, class _Allocator>
1970-
typename __tree<_Tp, _Compare, _Allocator>::iterator
1971-
__tree<_Tp, _Compare, _Allocator>::__node_insert_multi(const_iterator __p, __node_pointer __nd) {
1972-
__end_node_pointer __parent;
1973-
__node_base_pointer& __child = __find_leaf(__p, __parent, __nd->__get_value());
1974-
__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd));
1975-
return iterator(__nd);
1976-
}
1977-
19781820
template <class _Tp, class _Compare, class _Allocator>
19791821
typename __tree<_Tp, _Compare, _Allocator>::iterator
19801822
__tree<_Tp, _Compare, _Allocator>::__remove_node_pointer(__node_pointer __ptr) _NOEXCEPT {

libcxx/include/map

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,8 @@ public:
10151015
# endif
10161016

10171017
_LIBCPP_HIDE_FROM_ABI map& operator=(initializer_list<value_type> __il) {
1018-
__tree_.__assign_unique(__il.begin(), __il.end());
1018+
clear();
1019+
insert(__il.begin(), __il.end());
10191020
return *this;
10201021
}
10211022

@@ -1689,7 +1690,8 @@ public:
16891690
# endif
16901691

16911692
_LIBCPP_HIDE_FROM_ABI multimap& operator=(initializer_list<value_type> __il) {
1692-
__tree_.__assign_multi(__il.begin(), __il.end());
1693+
clear();
1694+
insert(__il.begin(), __il.end());
16931695
return *this;
16941696
}
16951697

libcxx/include/set

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,8 @@ public:
692692
# endif
693693

694694
_LIBCPP_HIDE_FROM_ABI set& operator=(initializer_list<value_type> __il) {
695-
__tree_.__assign_unique(__il.begin(), __il.end());
695+
clear();
696+
insert(__il.begin(), __il.end());
696697
return *this;
697698
}
698699

@@ -1136,7 +1137,8 @@ public:
11361137
# endif
11371138

11381139
_LIBCPP_HIDE_FROM_ABI multiset& operator=(initializer_list<value_type> __il) {
1139-
__tree_.__assign_multi(__il.begin(), __il.end());
1140+
clear();
1141+
insert(__il.begin(), __il.end());
11401142
return *this;
11411143
}
11421144

0 commit comments

Comments
 (0)