From 5f9164978b218fa65c53a59e91ea01831735f7a4 Mon Sep 17 00:00:00 2001 From: higher-performance Date: Thu, 24 Apr 2025 20:30:28 +0200 Subject: [PATCH] Optimize std::__tree::__assign_multi to insert the provided range at the end of the tree every time (#131030) This improves performance for the copy-assignment operators of associative containers such as `std::map`. This optimization already exists in other places in the codebase, and seems to have been missed here. --- libcxx/include/__tree | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libcxx/include/__tree b/libcxx/include/__tree index 247a5acfb148..bbf7c71962e9 100644 --- a/libcxx/include/__tree +++ b/libcxx/include/__tree @@ -1411,8 +1411,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