Skip to content

[libc++][NFC] Remove some __tree internal accessor functions #147266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 47 additions & 53 deletions libcxx/include/__tree
Original file line number Diff line number Diff line change
Expand Up @@ -865,17 +865,11 @@ public:

private:
_LIBCPP_HIDE_FROM_ABI const __node_allocator& __node_alloc() const _NOEXCEPT { return __node_alloc_; }
_LIBCPP_HIDE_FROM_ABI __end_node_pointer& __begin_node() _NOEXCEPT { return __begin_node_; }
_LIBCPP_HIDE_FROM_ABI const __end_node_pointer& __begin_node() const _NOEXCEPT { return __begin_node_; }

public:
_LIBCPP_HIDE_FROM_ABI allocator_type __alloc() const _NOEXCEPT { return allocator_type(__node_alloc()); }

private:
_LIBCPP_HIDE_FROM_ABI size_type& size() _NOEXCEPT { return __size_; }

public:
_LIBCPP_HIDE_FROM_ABI const size_type& size() const _NOEXCEPT { return __size_; }
_LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __size_; }
_LIBCPP_HIDE_FROM_ABI value_compare& value_comp() _NOEXCEPT { return __value_comp_; }
_LIBCPP_HIDE_FROM_ABI const value_compare& value_comp() const _NOEXCEPT { return __value_comp_; }

Expand Down Expand Up @@ -912,8 +906,8 @@ public:

_LIBCPP_HIDE_FROM_ABI ~__tree();

_LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return iterator(__begin_node()); }
_LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return const_iterator(__begin_node()); }
_LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return iterator(__begin_node_); }
_LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return const_iterator(__begin_node_); }
_LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { return iterator(__end_node()); }
_LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return const_iterator(__end_node()); }

Expand Down Expand Up @@ -1277,30 +1271,30 @@ template <class _Tp, class _Compare, class _Allocator>
__tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp) _NOEXCEPT_(
is_nothrow_default_constructible<__node_allocator>::value&& is_nothrow_copy_constructible<value_compare>::value)
: __size_(0), __value_comp_(__comp) {
__begin_node() = __end_node();
__begin_node_ = __end_node();
}

template <class _Tp, class _Compare, class _Allocator>
__tree<_Tp, _Compare, _Allocator>::__tree(const allocator_type& __a)
: __begin_node_(), __node_alloc_(__node_allocator(__a)), __size_(0) {
__begin_node() = __end_node();
__begin_node_ = __end_node();
}

template <class _Tp, class _Compare, class _Allocator>
__tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp, const allocator_type& __a)
: __begin_node_(), __node_alloc_(__node_allocator(__a)), __size_(0), __value_comp_(__comp) {
__begin_node() = __end_node();
__begin_node_ = __end_node();
}

// Precondition: size() != 0
// Precondition: __size_ != 0
template <class _Tp, class _Compare, class _Allocator>
typename __tree<_Tp, _Compare, _Allocator>::__node_pointer
__tree<_Tp, _Compare, _Allocator>::_DetachedTreeCache::__detach_from_tree(__tree* __t) _NOEXCEPT {
__node_pointer __cache = static_cast<__node_pointer>(__t->__begin_node());
__t->__begin_node() = __t->__end_node();
__node_pointer __cache = static_cast<__node_pointer>(__t->__begin_node_);
__t->__begin_node_ = __t->__end_node();
__t->__end_node()->__left_->__parent_ = nullptr;
__t->__end_node()->__left_ = nullptr;
__t->size() = 0;
__t->__size_ = 0;
// __cache->__left_ == nullptr
if (__cache->__right_ != nullptr)
__cache = static_cast<__node_pointer>(__cache->__right_);
Expand Down Expand Up @@ -1352,7 +1346,7 @@ void __tree<_Tp, _Compare, _Allocator>::__assign_unique(_ForwardIterator __first
is_same<_ItValueType, value_type>::value, "__assign_unique may only be called with the containers value type");
static_assert(
__has_forward_iterator_category<_ForwardIterator>::value, "__assign_unique requires a forward iterator");
if (size() != 0) {
if (__size_ != 0) {
_DetachedTreeCache __cache(this);
for (; __cache.__get() != nullptr && __first != __last; ++__first) {
if (__node_assign_unique(*__first, __cache.__get()).second)
Expand All @@ -1370,7 +1364,7 @@ void __tree<_Tp, _Compare, _Allocator>::__assign_multi(_InputIterator __first, _
typedef typename _ITraits::value_type _ItValueType;
static_assert(
is_same<_ItValueType, value_type>::value, "__assign_multi may only be called with the containers value_type");
if (size() != 0) {
if (__size_ != 0) {
_DetachedTreeCache __cache(this);
for (; __cache.__get() && __first != __last; ++__first) {
__assign_value(__cache.__get()->__value_, *__first);
Expand All @@ -1389,7 +1383,7 @@ __tree<_Tp, _Compare, _Allocator>::__tree(const __tree& __t)
__node_alloc_(__node_traits::select_on_container_copy_construction(__t.__node_alloc())),
__size_(0),
__value_comp_(__t.value_comp()) {
__begin_node() = __end_node();
__begin_node_ = __end_node();
}

template <class _Tp, class _Compare, class _Allocator>
Expand All @@ -1400,33 +1394,33 @@ __tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t) _NOEXCEPT_(
__node_alloc_(std::move(__t.__node_alloc_)),
__size_(__t.__size_),
__value_comp_(std::move(__t.__value_comp_)) {
if (size() == 0)
__begin_node() = __end_node();
if (__size_ == 0)
__begin_node_ = __end_node();
else {
__end_node()->__left_->__parent_ = static_cast<__end_node_pointer>(__end_node());
__t.__begin_node() = __t.__end_node();
__t.__begin_node_ = __t.__end_node();
__t.__end_node()->__left_ = nullptr;
__t.size() = 0;
__t.__size_ = 0;
}
}

template <class _Tp, class _Compare, class _Allocator>
__tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t, const allocator_type& __a)
: __node_alloc_(__node_allocator(__a)), __size_(0), __value_comp_(std::move(__t.value_comp())) {
if (__a == __t.__alloc()) {
if (__t.size() == 0)
__begin_node() = __end_node();
if (__t.__size_ == 0)
__begin_node_ = __end_node();
else {
__begin_node() = __t.__begin_node();
__begin_node_ = __t.__begin_node_;
__end_node()->__left_ = __t.__end_node()->__left_;
__end_node()->__left_->__parent_ = static_cast<__end_node_pointer>(__end_node());
size() = __t.size();
__t.__begin_node() = __t.__end_node();
__size_ = __t.__size_;
__t.__begin_node_ = __t.__end_node();
__t.__end_node()->__left_ = nullptr;
__t.size() = 0;
__t.__size_ = 0;
}
} else {
__begin_node() = __end_node();
__begin_node_ = __end_node();
}
}

Expand All @@ -1439,13 +1433,13 @@ void __tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, true_type)
__move_assign_alloc(__t);
__size_ = __t.__size_;
__value_comp_ = std::move(__t.__value_comp_);
if (size() == 0)
__begin_node() = __end_node();
if (__size_ == 0)
__begin_node_ = __end_node();
else {
__end_node()->__left_->__parent_ = static_cast<__end_node_pointer>(__end_node());
__t.__begin_node() = __t.__end_node();
__t.__begin_node_ = __t.__end_node();
__t.__end_node()->__left_ = nullptr;
__t.size() = 0;
__t.__size_ = 0;
}
}

Expand All @@ -1456,15 +1450,15 @@ void __tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, false_type) {
else {
value_comp() = std::move(__t.value_comp());
const_iterator __e = end();
if (size() != 0) {
if (__size_ != 0) {
_DetachedTreeCache __cache(this);
while (__cache.__get() != nullptr && __t.size() != 0) {
while (__cache.__get() != nullptr && __t.__size_ != 0) {
__assign_value(__cache.__get()->__value_, std::move(__t.remove(__t.begin())->__value_));
__node_insert_multi(__cache.__get());
__cache.__advance();
}
}
while (__t.size() != 0) {
while (__t.__size_ != 0) {
__insert_multi_from_orphaned_node(__e, std::move(__t.remove(__t.begin())->__value_));
}
}
Expand Down Expand Up @@ -1512,21 +1506,21 @@ void __tree<_Tp, _Compare, _Allocator>::swap(__tree& __t)
std::__swap_allocator(__node_alloc(), __t.__node_alloc());
swap(__size_, __t.__size_);
swap(__value_comp_, __t.__value_comp_);
if (size() == 0)
__begin_node() = __end_node();
if (__size_ == 0)
__begin_node_ = __end_node();
else
__end_node()->__left_->__parent_ = __end_node();
if (__t.size() == 0)
__t.__begin_node() = __t.__end_node();
if (__t.__size_ == 0)
__t.__begin_node_ = __t.__end_node();
else
__t.__end_node()->__left_->__parent_ = __t.__end_node();
}

template <class _Tp, class _Compare, class _Allocator>
void __tree<_Tp, _Compare, _Allocator>::clear() _NOEXCEPT {
destroy(__root());
size() = 0;
__begin_node() = __end_node();
__size_ = 0;
__begin_node_ = __end_node();
__end_node()->__left_ = nullptr;
}

Expand Down Expand Up @@ -1716,10 +1710,10 @@ void __tree<_Tp, _Compare, _Allocator>::__insert_node_at(
__new_node->__parent_ = __parent;
// __new_node->__is_black_ is initialized in __tree_balance_after_insert
__child = __new_node;
if (__begin_node()->__left_ != nullptr)
__begin_node() = static_cast<__end_node_pointer>(__begin_node()->__left_);
if (__begin_node_->__left_ != nullptr)
__begin_node_ = static_cast<__end_node_pointer>(__begin_node_->__left_);
std::__tree_balance_after_insert(__end_node()->__left_, __child);
++size();
++__size_;
}

template <class _Tp, class _Compare, class _Allocator>
Expand Down Expand Up @@ -1863,9 +1857,9 @@ typename __tree<_Tp, _Compare, _Allocator>::iterator
__tree<_Tp, _Compare, _Allocator>::__remove_node_pointer(__node_pointer __ptr) _NOEXCEPT {
iterator __r(__ptr);
++__r;
if (__begin_node() == __ptr)
__begin_node() = __r.__ptr_;
--size();
if (__begin_node_ == __ptr)
__begin_node_ = __r.__ptr_;
--__size_;
std::__tree_remove(__end_node()->__left_, static_cast<__node_base_pointer>(__ptr));
return __r;
}
Expand Down Expand Up @@ -2229,13 +2223,13 @@ template <class _Tp, class _Compare, class _Allocator>
typename __tree<_Tp, _Compare, _Allocator>::__node_holder
__tree<_Tp, _Compare, _Allocator>::remove(const_iterator __p) _NOEXCEPT {
__node_pointer __np = __p.__get_np();
if (__begin_node() == __p.__ptr_) {
if (__begin_node_ == __p.__ptr_) {
if (__np->__right_ != nullptr)
__begin_node() = static_cast<__end_node_pointer>(__np->__right_);
__begin_node_ = static_cast<__end_node_pointer>(__np->__right_);
else
__begin_node() = static_cast<__end_node_pointer>(__np->__parent_);
__begin_node_ = static_cast<__end_node_pointer>(__np->__parent_);
}
--size();
--__size_;
std::__tree_remove(__end_node()->__left_, static_cast<__node_base_pointer>(__np));
return __node_holder(__np, _Dp(__node_alloc(), true));
}
Expand Down
Loading