Unordered: Tweak node_construct functions.

[SVN r80381]
This commit is contained in:
Daniel James
2012-09-03 20:02:53 +00:00
parent d9f49f2b44
commit 31f3a10d33
4 changed files with 21 additions and 37 deletions

View File

@ -73,21 +73,21 @@ namespace boost { namespace unordered { namespace detail {
~node_constructor();
void construct_node();
void construct();
template <BOOST_UNORDERED_EMPLACE_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 <typename A0>
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>(a0)));
@ -132,7 +132,7 @@ namespace boost { namespace unordered { namespace detail {
}
template <typename Alloc>
void node_constructor<Alloc>::construct_node()
void node_constructor<Alloc>::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<std::ptrdiff_t>(this->bucket_count_))->next_ =

View File

@ -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);
}
}

View File

@ -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();
}
};

View File

@ -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);
}