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

Conversation

philnik777
Copy link
Contributor

No description provided.

@philnik777 philnik777 marked this pull request as ready for review July 16, 2025 08:33
@philnik777 philnik777 requested a review from a team as a code owner July 16, 2025 08:33
@philnik777 philnik777 merged commit 5009613 into llvm:main Jul 16, 2025
76 of 79 checks passed
@philnik777 philnik777 deleted the tree_remove_accessors branch July 16, 2025 08:33
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jul 16, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 16, 2025

@llvm/pr-subscribers-libcxx

Author: Nikolas Klauser (philnik777)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/147266.diff

1 Files Affected:

  • (modified) libcxx/include/__tree (+47-53)
diff --git a/libcxx/include/__tree b/libcxx/include/__tree
index 9d4ba3ad0639c..b6441d5ba90fe 100644
--- a/libcxx/include/__tree
+++ b/libcxx/include/__tree
@@ -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_; }
 
@@ -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()); }
 
@@ -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_);
@@ -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)
@@ -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);
@@ -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>
@@ -1400,13 +1394,13 @@ __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;
   }
 }
 
@@ -1414,19 +1408,19 @@ 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();
   }
 }
 
@@ -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;
   }
 }
 
@@ -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_));
     }
   }
@@ -1512,12 +1506,12 @@ 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();
 }
@@ -1525,8 +1519,8 @@ void __tree<_Tp, _Compare, _Allocator>::swap(__tree& __t)
 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;
 }
 
@@ -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>
@@ -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;
 }
@@ -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));
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants