2525#include < __memory/swap_allocator.h>
2626#include < __memory/unique_ptr.h>
2727#include < __new/launder.h>
28+ #include < __type_traits/conditional.h>
2829#include < __type_traits/copy_cvref.h>
2930#include < __type_traits/enable_if.h>
3031#include < __type_traits/invoke.h>
3435#include < __type_traits/is_same.h>
3536#include < __type_traits/is_specialization.h>
3637#include < __type_traits/is_swappable.h>
38+ #include < __type_traits/is_trivially_copyable.h>
3739#include < __type_traits/remove_const.h>
3840#include < __utility/forward.h>
3941#include < __utility/lazy_synth_three_way_comparator.h>
@@ -1314,7 +1316,7 @@ private:
13141316 };
13151317
13161318 class __tree_deleter {
1317- __node_allocator& __alloc_;
1319+ __conditional_t <__is_cheap_to_copy< __node_allocator>, __node_allocator, __node_allocator&> __alloc_;
13181320
13191321 public:
13201322 using pointer = __node_pointer;
@@ -1348,15 +1350,14 @@ private:
13481350 _LIBCPP_HIDE_FROM_ABI
13491351#endif
13501352 __node_pointer
1351- __copy_construct_tree (__node_pointer __src) {
1352- if (!__src)
1353- return nullptr ;
1354-
1353+ __copy_construct_tree_impl (__node_pointer __src) {
13551354 __node_holder __new_node = __construct_node (__src->__get_value ());
13561355
13571356 unique_ptr<__node, __tree_deleter> __left (
1358- __copy_construct_tree (static_cast <__node_pointer>(__src->__left_ )), __node_alloc_);
1359- __node_pointer __right = __copy_construct_tree (static_cast <__node_pointer>(__src->__right_ ));
1357+ __src->__left_ ? __copy_construct_tree_impl (static_cast <__node_pointer>(__src->__left_ )) : nullptr ,
1358+ __node_alloc_);
1359+ __node_pointer __right =
1360+ __src->__right_ ? __copy_construct_tree_impl (static_cast <__node_pointer>(__src->__right_ )) : nullptr ;
13601361
13611362 __node_pointer __new_node_ptr = __new_node.release ();
13621363
@@ -1370,6 +1371,10 @@ private:
13701371 return __new_node_ptr;
13711372 }
13721373
1374+ _LIBCPP_HIDE_FROM_ABI __node_pointer __copy_construct_tree (__node_pointer __src) {
1375+ return __src ? __copy_construct_tree_impl (__src) : nullptr ;
1376+ }
1377+
13731378 // This copy assignment will always produce a correct red-black-tree assuming the incoming tree is correct, since our
13741379 // own tree is a red-black-tree and the incoming tree is a red-black-tree. The invariants of a red-black-tree are
13751380 // temporarily not met until all of the incoming red-black tree is copied.
0 commit comments