[libcxx-commits] [libcxx] Optimize std::__tree::__assign_multi to insert the provided range at the end of the tree every time (PR #131030)
via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Mar 12 13:59:46 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: None (higher-performance)
<details>
<summary>Changes</summary>
This improves performance for the copy-assignment operators of associative containers such as `std::map`.
Note that this optimization already exists in other places, e.g.:
https://github.com/llvm/llvm-project/blob/15e6bb6224177805d8b6a8268f08a2b88ae4dd70/libcxx/include/map#L1217-L1218
---
Full diff: https://github.com/llvm/llvm-project/pull/131030.diff
1 Files Affected:
- (modified) libcxx/include/__tree (+2-1)
``````````diff
diff --git a/libcxx/include/__tree b/libcxx/include/__tree
index c627641d5d86f..c07de5c95b0dc 100644
--- a/libcxx/include/__tree
+++ b/libcxx/include/__tree
@@ -1432,8 +1432,9 @@ void __tree<_Tp, _Compare, _Allocator>::__assign_multi(_InputIterator __first, _
__cache.__advance();
}
}
+ const_iterator __e = end();
for (; __first != __last; ++__first)
- __insert_multi(_NodeTypes::__get_value(*__first));
+ __insert_multi(__e, _NodeTypes::__get_value(*__first));
}
template <class _Tp, class _Compare, class _Allocator>
``````````
</details>
https://github.com/llvm/llvm-project/pull/131030
More information about the libcxx-commits
mailing list