[libcxx-commits] [libcxx] [libc++] Optimize copy construction and assignment of __tree (PR #151304)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jul 30 07:36:26 PDT 2025


================
@@ -1327,11 +1418,18 @@ void __tree<_Tp, _Compare, _Allocator>::__assign_multi(_InputIterator __first, _
 
 template <class _Tp, class _Compare, class _Allocator>
 __tree<_Tp, _Compare, _Allocator>::__tree(const __tree& __t)
-    : __begin_node_(),
+    : __begin_node_(__end_node()),
       __node_alloc_(__node_traits::select_on_container_copy_construction(__t.__node_alloc())),
       __size_(0),
       __value_comp_(__t.value_comp()) {
-  __begin_node_ = __end_node();
+  if (__t.__size_ == 0)
+    return;
+
+  __end_node_.__left_ =
----------------
ldionne wrote:

I think some of these `__end_node_.__left_` accesses should be replaced by calls to the `__root()` function or similar, to be a bit more self-documenting.

https://github.com/llvm/llvm-project/pull/151304


More information about the libcxx-commits mailing list