Skip to content

Commit 1995180

Browse files
committed
[libc++] Optimize __tree::__erase_unique
1 parent d70e50b commit 1995180

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

libcxx/docs/ReleaseNotes/22.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Improvements and New Features
4545

4646
- The performance of ``map::map(const map&)`` has been improved up to 2.3x
4747
- The performance of ``map::operator=(const map&)`` has been improved by up to 11x
48+
- The performance of ``map::erase`` and ``set::erase`` has been improved by up to 2x
49+
- The performance of ``find(key)`` in all associative containers has been improved by up to 2.3x
4850

4951
Deprecations and Removals
5052
-------------------------

libcxx/include/__tree

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,9 +1009,22 @@ public:
10091009
__insert_node_at(__end_node_pointer __parent, __node_base_pointer& __child, __node_base_pointer __new_node) _NOEXCEPT;
10101010

10111011
template <class _Key>
1012-
_LIBCPP_HIDE_FROM_ABI iterator find(const _Key& __v);
1012+
_LIBCPP_HIDE_FROM_ABI iterator find(const _Key& __key) {
1013+
__end_node_pointer __parent;
1014+
__node_base_pointer __match = __find_equal(__parent, __key);
1015+
if (__match == nullptr)
1016+
return end();
1017+
return iterator(static_cast<__node_pointer>(__match));
1018+
}
1019+
10131020
template <class _Key>
1014-
_LIBCPP_HIDE_FROM_ABI const_iterator find(const _Key& __v) const;
1021+
_LIBCPP_HIDE_FROM_ABI const_iterator find(const _Key& __key) const {
1022+
__end_node_pointer __parent;
1023+
__node_base_pointer __match = __find_equal(__parent, __key);
1024+
if (__match == nullptr)
1025+
return end();
1026+
return const_iterator(static_cast<__node_pointer>(__match));
1027+
}
10151028

10161029
template <class _Key>
10171030
_LIBCPP_HIDE_FROM_ABI size_type __count_unique(const _Key& __k) const;
@@ -2031,25 +2044,6 @@ __tree<_Tp, _Compare, _Allocator>::__erase_multi(const _Key& __k) {
20312044
return __r;
20322045
}
20332046

2034-
template <class _Tp, class _Compare, class _Allocator>
2035-
template <class _Key>
2036-
typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::find(const _Key& __v) {
2037-
iterator __p = __lower_bound(__v, __root(), __end_node());
2038-
if (__p != end() && !value_comp()(__v, *__p))
2039-
return __p;
2040-
return end();
2041-
}
2042-
2043-
template <class _Tp, class _Compare, class _Allocator>
2044-
template <class _Key>
2045-
typename __tree<_Tp, _Compare, _Allocator>::const_iterator
2046-
__tree<_Tp, _Compare, _Allocator>::find(const _Key& __v) const {
2047-
const_iterator __p = __lower_bound(__v, __root(), __end_node());
2048-
if (__p != end() && !value_comp()(__v, *__p))
2049-
return __p;
2050-
return end();
2051-
}
2052-
20532047
template <class _Tp, class _Compare, class _Allocator>
20542048
template <class _Key>
20552049
typename __tree<_Tp, _Compare, _Allocator>::size_type

0 commit comments

Comments
 (0)