This is an automated email from the ASF dual-hosted git repository. astitcher pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/qpid-proton.git
commit c5ac76e7f138b78be967f2b3906d6e74b60c748d Author: Andrew Stitcher <[email protected]> AuthorDate: Wed Jan 12 11:27:50 2022 -0500 PROTON-2481: Make the new constructors more efficient Directly construct the internal std::map rather than coding up the value immediately. Also introduce an untemplated assignment operator that takes std::map that is much more efficient than the templated version. --- cpp/include/proton/map.hpp | 3 +++ cpp/src/link_test.cpp | 15 ++++----------- cpp/src/map.cpp | 21 +++++++++++++++++---- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/cpp/include/proton/map.hpp b/cpp/include/proton/map.hpp index 86874c5..f8491f3 100644 --- a/cpp/include/proton/map.hpp +++ b/cpp/include/proton/map.hpp @@ -84,6 +84,9 @@ class PN_CPP_CLASS_EXTERN map { /// Copy a std::map. PN_CPP_EXTERN map(const std::map<K, T>&); + /// Copy a std::map. + PN_CPP_EXTERN map& operator=(const std::map<K, T>&); + /// Initializer_list constructor. PN_CPP_EXTERN map(const std::initializer_list<std::pair<const K, T>>&); diff --git a/cpp/src/link_test.cpp b/cpp/src/link_test.cpp index 066381c..75d5f63 100644 --- a/cpp/src/link_test.cpp +++ b/cpp/src/link_test.cpp @@ -78,21 +78,16 @@ class test_server : public proton::messaging_handler { void on_sender_open(proton::sender& s) override { ASSERT(s.source().dynamic()); ASSERT(s.source().address().empty()); - property_map p; - p = std::map<proton::symbol, proton::value>{ + property_map p = { {proton::symbol("supported-dist-modes"), proton::symbol("copy")} }; ASSERT_EQUAL(s.source().dynamic_properties(), p); - property_map sp; - sp = std::map<proton::symbol, proton::value>{ - {proton::symbol("supported-dist-modes"), proton::symbol("move")} - }; proton::source_options opts; opts.address(DYNAMIC_ADDRESS) // This fails due to a bug in the C++ bindings - PROTON-2480 // .dynamic(true) - .dynamic_properties(sp); + .dynamic_properties({{proton::symbol("supported-dist-modes"), proton::symbol("move")}}); s.open(proton::sender_options().source(opts)); listener.stop(); } @@ -106,8 +101,7 @@ class test_client : public proton::messaging_handler { test_client (const std::string& s) : url(s) {} void on_container_start(proton::container& c) override { - property_map sp; - sp = std::map<proton::symbol, proton::value>{ + property_map sp = std::map<proton::symbol, proton::value>{ {proton::symbol("supported-dist-modes"), proton::symbol("copy")} }; proton::source_options opts; @@ -120,8 +114,7 @@ class test_client : public proton::messaging_handler { // This fails due to a bug in the c++ bindings - PROTON-2480 // ASSERT(r.source().dynamic()); ASSERT_EQUAL(DYNAMIC_ADDRESS, r.source().address()); - property_map m; - m = std::map<proton::symbol, proton::value>{ + property_map m = std::map<proton::symbol, proton::value>{ {proton::symbol("supported-dist-modes"), proton::symbol("move")} }; ASSERT_EQUAL(m, r.source().dynamic_properties()); diff --git a/cpp/src/map.cpp b/cpp/src/map.cpp index 6c9d442..c152d77 100644 --- a/cpp/src/map.cpp +++ b/cpp/src/map.cpp @@ -40,7 +40,14 @@ namespace proton { // use std::map as the actual map implementation type template <class K, class T> -class map_type_impl : public std::map<K, T> {}; +class map_type_impl : public std::map<K, T> { + // Inherit constructors from std::map for convenience + using std::map<K,T>::map; + +public: + map_type_impl() = default; + map_type_impl(const std::map<K, T>& x) : std::map<K, T>(x) {}; +}; template <class K, class T> map<K,T>::map() {} @@ -49,11 +56,17 @@ template <class K, class T> map<K,T>::map(const map& x) { *this = x; } template <class K, class T> -map<K, T>::map(const std::map<K, T>& x) { *this = x; } +map<K,T>::map(const std::initializer_list<std::pair<const K, T>>& x) : map_(new map_type(x)) { +} + +template <class K, class T> +map<K,T>::map(const std::map<K, T>& x) : map_(new map_type(x)) { +} template <class K, class T> -map<K, T>::map(const std::initializer_list<std::pair<const K, T>>& x) { - *this = std::map<K, T>(x); +map<K,T>& map<K,T>::operator=(const std::map<K, T>& x) { + map_.reset(new map_type(x)); + return *this; } template <class K, class T> --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
