From ab62d334958e906af0aaee6f9a5dd50d4910505d Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sun, 12 Apr 2009 10:25:38 +0000 Subject: [PATCH] Merged revisions 52224 via svnmerge from https://svn.boost.org/svn/boost/trunk ........ r52224 | danieljames | 2009-04-06 23:51:36 +0100 (Mon, 06 Apr 2009) | 1 line Avoid an unnecessary copy in 'operator[]' ........ [SVN r52346] --- .../boost/unordered/detail/hash_table_impl.hpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/include/boost/unordered/detail/hash_table_impl.hpp b/include/boost/unordered/detail/hash_table_impl.hpp index a8e86ad4..e7cdc5b9 100644 --- a/include/boost/unordered/detail/hash_table_impl.hpp +++ b/include/boost/unordered/detail/hash_table_impl.hpp @@ -215,6 +215,22 @@ namespace boost { } #endif + template + void construct_pair(K const& k, M*) + { + BOOST_ASSERT(!node_); + node_constructed_ = false; + value_constructed_ = false; + + node_ = allocators_.node_alloc_.allocate(1); + + allocators_.node_alloc_.construct(node_, node()); + node_constructed_ = true; + + new(node_->address()) value_type(k, M()); + value_constructed_ = true; + } + node_ptr get() const { BOOST_ASSERT(node_); @@ -1757,7 +1773,7 @@ namespace boost { // Create the node before rehashing in case it throws an // exception (need strong safety in such a case). node_constructor a(data_.allocators_); - a.construct(value_type(k, mapped_type())); + a.construct_pair(k, (mapped_type*) 0); // reserve has basic exception safety if the hash function // throws, strong otherwise.