[libcxx-commits] [libcxx] [libc++] Optimize multi{map, set}::insert(InputIterator, InputIterator) (PR #152691)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Aug 14 00:52:42 PDT 2025
================
@@ -970,6 +970,36 @@ public:
__emplace_hint_multi(__p, std::move(__value));
}
+ template <class _InIter, class _Sent>
+ _LIBCPP_HIDE_FROM_ABI void __insert_range_multi(_InIter __first, _Sent __last) {
+ if (__first == __last)
+ return;
+
+ if (__root() == nullptr) { // Make sure we always have a root node
+ __node_holder __node = __construct_node(*__first);
+ __insert_node_at(__end_node(), __end_node()->__left_, static_cast<__node_base_pointer>(__node.release()));
+ ++__first;
+ }
+
+ auto __max_node = static_cast<__node_pointer>(std::__tree_max(static_cast<__node_base_pointer>(__root())));
+ __node_pointer __last_insertion = __root();
+
+ for (; __first != __last; ++__first) {
+ __node_holder __node = __construct_node(*__first);
+ if (!value_comp()(__node->__get_value(), __max_node->__get_value())) { // __node >= __max_val
+ __insert_node_at(static_cast<__end_node_pointer>(__max_node),
+ __max_node->__right_,
+ static_cast<__node_base_pointer>(__node.get()));
+ __max_node = __node.release();
+ } else {
+ __end_node_pointer __parent;
+ __node_base_pointer& __child = __find_leaf(++iterator(__last_insertion), __parent, __node->__value_);
----------------
philnik777 wrote:
I've updated the description.
https://github.com/llvm/llvm-project/pull/152691
More information about the libcxx-commits
mailing list