diff --git a/libcxx/benchmarks/map.bench.cpp b/libcxx/benchmarks/map.bench.cpp --- a/libcxx/benchmarks/map.bench.cpp +++ b/libcxx/benchmarks/map.bench.cpp @@ -168,6 +168,29 @@ std::string name() const { return "BM_ConstructorMove" + baseName(); } }; +struct CopyAssignment : Base { + using Base::Base; + + void run(benchmark::State& State) const { + auto Data = makeTestingSets(MapSize, Mode::Hit, Shuffle::None, 1); + auto& Map = Data.Maps.front(); + while (State.KeepRunningBatch(MapSize)) { +#ifndef VALIDATE + std::map M; + M = Map; + benchmark::DoNotOptimize(M); +#else + std::map M; + M = Map; + if (M != Map) + State.SkipWithError("Map copy assignment not identical"); +#endif + } + } + + std::string name() const { return "BM_CopyAssignment" + baseName(); } +}; + //*******************************************************************| // Capacity | //*******************************************************************| @@ -1006,6 +1029,7 @@ makeCartesianProductBenchmark(MapSize); makeCartesianProductBenchmark(MapSize); makeCartesianProductBenchmark(MapSize); + makeCartesianProductBenchmark(MapSize); // Capacity makeCartesianProductBenchmark(MapSize); diff --git a/libcxx/include/__tree b/libcxx/include/__tree --- a/libcxx/include/__tree +++ b/libcxx/include/__tree @@ -1095,7 +1095,6 @@ explicit __tree(const allocator_type& __a); __tree(const value_compare& __comp, const allocator_type& __a); __tree(const __tree& __t); - __tree& operator=(const __tree& __t); template void __assign_unique(_ForwardIterator __first, _ForwardIterator __last); template @@ -1534,6 +1533,8 @@ template friend class _LIBCPP_TEMPLATE_VIS map; template friend class _LIBCPP_TEMPLATE_VIS multimap; + template friend class _LIBCPP_TEMPLATE_VIS set; + template friend class _LIBCPP_TEMPLATE_VIS multiset; }; template @@ -1609,19 +1610,6 @@ return static_cast<__node_pointer>(_VSTD::__tree_leaf(__cache->__left_)); } -template -__tree<_Tp, _Compare, _Allocator>& -__tree<_Tp, _Compare, _Allocator>::operator=(const __tree& __t) -{ - if (this != _VSTD::addressof(__t)) - { - value_comp() = __t.value_comp(); - __copy_assign_alloc(__t); - __assign_multi(__t.begin(), __t.end()); - } - return *this; -} - template template void diff --git a/libcxx/include/map b/libcxx/include/map --- a/libcxx/include/map +++ b/libcxx/include/map @@ -1077,16 +1077,12 @@ _LIBCPP_INLINE_VISIBILITY map& operator=(const map& __m) { -#ifndef _LIBCPP_CXX03_LANG - __tree_ = __m.__tree_; -#else if (this != _VSTD::addressof(__m)) { __tree_.clear(); __tree_.value_comp() = __m.__tree_.value_comp(); __tree_.__copy_assign_alloc(__m.__tree_); insert(__m.begin(), __m.end()); } -#endif return *this; } @@ -1863,16 +1859,12 @@ _LIBCPP_INLINE_VISIBILITY multimap& operator=(const multimap& __m) { -#ifndef _LIBCPP_CXX03_LANG - __tree_ = __m.__tree_; -#else if (this != _VSTD::addressof(__m)) { __tree_.clear(); __tree_.value_comp() = __m.__tree_.value_comp(); __tree_.__copy_assign_alloc(__m.__tree_); insert(__m.begin(), __m.end()); } -#endif return *this; } diff --git a/libcxx/include/set b/libcxx/include/set --- a/libcxx/include/set +++ b/libcxx/include/set @@ -591,7 +591,12 @@ _LIBCPP_INLINE_VISIBILITY set& operator=(const set& __s) { - __tree_ = __s.__tree_; + if (this != _VSTD::addressof(__s)) { + __tree_.clear(); + __tree_.value_comp() = __s.__tree_.value_comp(); + __tree_.__copy_assign_alloc(__s.__tree_); + insert(__s.begin(), __s.end()); + } return *this; } @@ -1125,7 +1130,12 @@ _LIBCPP_INLINE_VISIBILITY multiset& operator=(const multiset& __s) { - __tree_ = __s.__tree_; + if (this != _VSTD::addressof(__s)) { + __tree_.clear(); + __tree_.value_comp() = __s.__tree_.value_comp(); + __tree_.__copy_assign_alloc(__s.__tree_); + insert(__s.begin(), __s.end()); + } return *this; }