[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:25 PDT 2025
================
@@ -1277,11 +1351,28 @@ __tree<_Tp, _Compare, _Allocator>::_DetachedTreeCache::__detach_next(__node_poin
template <class _Tp, class _Compare, class _Allocator>
__tree<_Tp, _Compare, _Allocator>& __tree<_Tp, _Compare, _Allocator>::operator=(const __tree& __t) {
- if (this != std::addressof(__t)) {
- value_comp() = __t.value_comp();
- __copy_assign_alloc(__t);
- __assign_multi(__t.begin(), __t.end());
+ if (this == std::addressof(__t))
+ return *this;
+
+ value_comp() = __t.value_comp();
+ __copy_assign_alloc(__t);
+
+ if (__t.size() == 0) {
+ clear();
+ return *this;
+ }
----------------
ldionne wrote:
Is there a reason why we need to handle this as a special case? It's just intuition, but I'd be tempted to think that we might have a bug (or at least a landmine waiting to blow up) in `__copy_assign_tree` if this special case is required.
https://github.com/llvm/llvm-project/pull/151304
More information about the libcxx-commits
mailing list