From 31f3a10d33a51d5a0aa1d97597d9dd6e3a524283 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Mon, 3 Sep 2012 20:02:53 +0000 Subject: [PATCH] Unordered: Tweak node_construct functions. [SVN r80381] --- include/boost/unordered/detail/buckets.hpp | 20 +++++++++---------- include/boost/unordered/detail/equivalent.hpp | 12 ++++------- include/boost/unordered/detail/table.hpp | 6 ++---- include/boost/unordered/detail/unique.hpp | 20 ++++++------------- 4 files changed, 21 insertions(+), 37 deletions(-) diff --git a/include/boost/unordered/detail/buckets.hpp b/include/boost/unordered/detail/buckets.hpp index e658d5b0..fb8f3edc 100644 --- a/include/boost/unordered/detail/buckets.hpp +++ b/include/boost/unordered/detail/buckets.hpp @@ -73,21 +73,21 @@ namespace boost { namespace unordered { namespace detail { ~node_constructor(); - void construct_node(); + void construct(); template - void construct_value(BOOST_UNORDERED_EMPLACE_ARGS) + void construct_with_value(BOOST_UNORDERED_EMPLACE_ARGS) { - BOOST_ASSERT(node_ && node_constructed_ && !value_constructed_); + construct(); boost::unordered::detail::construct_value_impl( alloc_, node_->value_ptr(), BOOST_UNORDERED_EMPLACE_FORWARD); value_constructed_ = true; } template - void construct_value2(BOOST_FWD_REF(A0) a0) + void construct_with_value2(BOOST_FWD_REF(A0) a0) { - BOOST_ASSERT(node_ && node_constructed_ && !value_constructed_); + construct(); boost::unordered::detail::construct_value_impl( alloc_, node_->value_ptr(), BOOST_UNORDERED_EMPLACE_ARGS1(boost::forward(a0))); @@ -132,7 +132,7 @@ namespace boost { namespace unordered { namespace detail { } template - void node_constructor::construct_node() + void node_constructor::construct() { if(!node_) { node_constructed_ = false; @@ -228,8 +228,7 @@ namespace boost { namespace unordered { namespace detail { return p; } else { - this->construct_node(); - this->construct_value2(v); + this->construct_with_value2(v); return base::release(); } } @@ -244,8 +243,7 @@ namespace boost { namespace unordered { namespace detail { return p; } else { - this->construct_node(); - this->construct_value2(boost::move(v)); + this->construct_with_value2(boost::move(v)); return base::release(); } } @@ -853,7 +851,7 @@ namespace boost { namespace unordered { namespace detail { else if (bucket::extra_node) { node_constructor a(this->node_alloc()); - a.construct_node(); + a.construct(); (constructor.get() + static_cast(this->bucket_count_))->next_ = diff --git a/include/boost/unordered/detail/equivalent.hpp b/include/boost/unordered/detail/equivalent.hpp index 6ac10fdb..177fc86f 100644 --- a/include/boost/unordered/detail/equivalent.hpp +++ b/include/boost/unordered/detail/equivalent.hpp @@ -487,8 +487,7 @@ namespace boost { namespace unordered { namespace detail { iterator emplace(BOOST_UNORDERED_EMPLACE_ARGS) { node_constructor a(this->node_alloc()); - a.construct_node(); - a.construct_value(BOOST_UNORDERED_EMPLACE_FORWARD); + a.construct_with_value(BOOST_UNORDERED_EMPLACE_FORWARD); return iterator(emplace_impl(a)); } @@ -507,8 +506,7 @@ namespace boost { namespace unordered { namespace detail { std::size_t distance = boost::unordered::detail::distance(i, j); if(distance == 1) { node_constructor a(this->node_alloc()); - a.construct_node(); - a.construct_value2(*i); + a.construct_with_value2(*i); emplace_impl(a); } else { @@ -517,8 +515,7 @@ namespace boost { namespace unordered { namespace detail { node_constructor a(this->node_alloc()); for (; i != j; ++i) { - a.construct_node(); - a.construct_value2(*i); + a.construct_with_value2(*i); emplace_impl_no_rehash(a); } } @@ -530,8 +527,7 @@ namespace boost { namespace unordered { namespace detail { { node_constructor a(this->node_alloc()); for (; i != j; ++i) { - a.construct_node(); - a.construct_value2(*i); + a.construct_with_value2(*i); emplace_impl(a); } } diff --git a/include/boost/unordered/detail/table.hpp b/include/boost/unordered/detail/table.hpp index f7a1c325..19663f48 100644 --- a/include/boost/unordered/detail/table.hpp +++ b/include/boost/unordered/detail/table.hpp @@ -67,8 +67,7 @@ namespace boost { namespace unordered { namespace detail { typename node_allocator_traits::pointer create( typename node_allocator_traits::value_type::value_type const& v) { - constructor.construct_node(); - constructor.construct_value2(v); + constructor.construct_with_value2(v); return constructor.release(); } }; @@ -86,8 +85,7 @@ namespace boost { namespace unordered { namespace detail { typename node_allocator_traits::pointer create( typename node_allocator_traits::value_type::value_type& v) { - constructor.construct_node(); - constructor.construct_value2(boost::move(v)); + constructor.construct_with_value2(boost::move(v)); return constructor.release(); } }; diff --git a/include/boost/unordered/detail/unique.hpp b/include/boost/unordered/detail/unique.hpp index 20311435..37f70466 100644 --- a/include/boost/unordered/detail/unique.hpp +++ b/include/boost/unordered/detail/unique.hpp @@ -349,9 +349,7 @@ namespace boost { namespace unordered { namespace detail { // Create the node before rehashing in case it throws an // exception (need strong safety in such a case). node_constructor a(this->node_alloc()); - a.construct_node(); - - a.construct_value(BOOST_UNORDERED_EMPLACE_ARGS3( + a.construct_with_value(BOOST_UNORDERED_EMPLACE_ARGS3( boost::unordered::piecewise_construct, boost::make_tuple(k), boost::make_tuple())); @@ -413,8 +411,7 @@ namespace boost { namespace unordered { namespace detail { // Create the node before rehashing in case it throws an // exception (need strong safety in such a case). node_constructor a(this->node_alloc()); - a.construct_node(); - a.construct_value(BOOST_UNORDERED_EMPLACE_FORWARD); + a.construct_with_value(BOOST_UNORDERED_EMPLACE_FORWARD); // reserve has basic exception safety if the hash function // throws, strong otherwise. @@ -442,8 +439,7 @@ namespace boost { namespace unordered { namespace detail { // Don't have a key, so construct the node first in order // to be able to lookup the position. node_constructor a(this->node_alloc()); - a.construct_node(); - a.construct_value(BOOST_UNORDERED_EMPLACE_FORWARD); + a.construct_with_value(BOOST_UNORDERED_EMPLACE_FORWARD); return emplace_impl_with_node(a); } @@ -490,8 +486,7 @@ namespace boost { namespace unordered { namespace detail { InputIt i, InputIt j) { std::size_t key_hash = this->hash(k); - a.construct_node(); - a.construct_value2(*i); + a.construct_with_value2(*i); this->reserve_for_insert(this->size_ + boost::unordered::detail::insert_size(i, j)); this->add_node(a, key_hash); @@ -506,9 +501,7 @@ namespace boost { namespace unordered { namespace detail { iterator pos = this->find_node(key_hash, k); if (!pos.node_) { - a.construct_node(); - a.construct_value2(*i); - + a.construct_with_value2(*i); if(this->size_ + 1 > this->max_load_) this->reserve_for_insert(this->size_ + boost::unordered::detail::insert_size(i, j)); @@ -524,8 +517,7 @@ namespace boost { namespace unordered { namespace detail { node_constructor a(this->node_alloc()); do { - a.construct_node(); - a.construct_value2(*i); + a.construct_with_value2(*i); emplace_impl_with_node(a); } while(++i != j); }