mirror of
https://github.com/boostorg/unordered.git
synced 2025-07-30 03:17:15 +02:00
Unordered: Tweak node_construct functions.
[SVN r80381]
This commit is contained in:
@ -73,21 +73,21 @@ namespace boost { namespace unordered { namespace detail {
|
|||||||
|
|
||||||
~node_constructor();
|
~node_constructor();
|
||||||
|
|
||||||
void construct_node();
|
void construct();
|
||||||
|
|
||||||
template <BOOST_UNORDERED_EMPLACE_TEMPLATE>
|
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(
|
boost::unordered::detail::construct_value_impl(
|
||||||
alloc_, node_->value_ptr(), BOOST_UNORDERED_EMPLACE_FORWARD);
|
alloc_, node_->value_ptr(), BOOST_UNORDERED_EMPLACE_FORWARD);
|
||||||
value_constructed_ = true;
|
value_constructed_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename A0>
|
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(
|
boost::unordered::detail::construct_value_impl(
|
||||||
alloc_, node_->value_ptr(),
|
alloc_, node_->value_ptr(),
|
||||||
BOOST_UNORDERED_EMPLACE_ARGS1(boost::forward<A0>(a0)));
|
BOOST_UNORDERED_EMPLACE_ARGS1(boost::forward<A0>(a0)));
|
||||||
@ -132,7 +132,7 @@ namespace boost { namespace unordered { namespace detail {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename Alloc>
|
template <typename Alloc>
|
||||||
void node_constructor<Alloc>::construct_node()
|
void node_constructor<Alloc>::construct()
|
||||||
{
|
{
|
||||||
if(!node_) {
|
if(!node_) {
|
||||||
node_constructed_ = false;
|
node_constructed_ = false;
|
||||||
@ -228,8 +228,7 @@ namespace boost { namespace unordered { namespace detail {
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this->construct_node();
|
this->construct_with_value2(v);
|
||||||
this->construct_value2(v);
|
|
||||||
return base::release();
|
return base::release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -244,8 +243,7 @@ namespace boost { namespace unordered { namespace detail {
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this->construct_node();
|
this->construct_with_value2(boost::move(v));
|
||||||
this->construct_value2(boost::move(v));
|
|
||||||
return base::release();
|
return base::release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -853,7 +851,7 @@ namespace boost { namespace unordered { namespace detail {
|
|||||||
else if (bucket::extra_node)
|
else if (bucket::extra_node)
|
||||||
{
|
{
|
||||||
node_constructor a(this->node_alloc());
|
node_constructor a(this->node_alloc());
|
||||||
a.construct_node();
|
a.construct();
|
||||||
|
|
||||||
(constructor.get() +
|
(constructor.get() +
|
||||||
static_cast<std::ptrdiff_t>(this->bucket_count_))->next_ =
|
static_cast<std::ptrdiff_t>(this->bucket_count_))->next_ =
|
||||||
|
@ -487,8 +487,7 @@ namespace boost { namespace unordered { namespace detail {
|
|||||||
iterator emplace(BOOST_UNORDERED_EMPLACE_ARGS)
|
iterator emplace(BOOST_UNORDERED_EMPLACE_ARGS)
|
||||||
{
|
{
|
||||||
node_constructor a(this->node_alloc());
|
node_constructor a(this->node_alloc());
|
||||||
a.construct_node();
|
a.construct_with_value(BOOST_UNORDERED_EMPLACE_FORWARD);
|
||||||
a.construct_value(BOOST_UNORDERED_EMPLACE_FORWARD);
|
|
||||||
|
|
||||||
return iterator(emplace_impl(a));
|
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);
|
std::size_t distance = boost::unordered::detail::distance(i, j);
|
||||||
if(distance == 1) {
|
if(distance == 1) {
|
||||||
node_constructor a(this->node_alloc());
|
node_constructor a(this->node_alloc());
|
||||||
a.construct_node();
|
a.construct_with_value2(*i);
|
||||||
a.construct_value2(*i);
|
|
||||||
emplace_impl(a);
|
emplace_impl(a);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -517,8 +515,7 @@ namespace boost { namespace unordered { namespace detail {
|
|||||||
|
|
||||||
node_constructor a(this->node_alloc());
|
node_constructor a(this->node_alloc());
|
||||||
for (; i != j; ++i) {
|
for (; i != j; ++i) {
|
||||||
a.construct_node();
|
a.construct_with_value2(*i);
|
||||||
a.construct_value2(*i);
|
|
||||||
emplace_impl_no_rehash(a);
|
emplace_impl_no_rehash(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -530,8 +527,7 @@ namespace boost { namespace unordered { namespace detail {
|
|||||||
{
|
{
|
||||||
node_constructor a(this->node_alloc());
|
node_constructor a(this->node_alloc());
|
||||||
for (; i != j; ++i) {
|
for (; i != j; ++i) {
|
||||||
a.construct_node();
|
a.construct_with_value2(*i);
|
||||||
a.construct_value2(*i);
|
|
||||||
emplace_impl(a);
|
emplace_impl(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,8 +67,7 @@ namespace boost { namespace unordered { namespace detail {
|
|||||||
typename node_allocator_traits::pointer create(
|
typename node_allocator_traits::pointer create(
|
||||||
typename node_allocator_traits::value_type::value_type const& v)
|
typename node_allocator_traits::value_type::value_type const& v)
|
||||||
{
|
{
|
||||||
constructor.construct_node();
|
constructor.construct_with_value2(v);
|
||||||
constructor.construct_value2(v);
|
|
||||||
return constructor.release();
|
return constructor.release();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -86,8 +85,7 @@ namespace boost { namespace unordered { namespace detail {
|
|||||||
typename node_allocator_traits::pointer create(
|
typename node_allocator_traits::pointer create(
|
||||||
typename node_allocator_traits::value_type::value_type& v)
|
typename node_allocator_traits::value_type::value_type& v)
|
||||||
{
|
{
|
||||||
constructor.construct_node();
|
constructor.construct_with_value2(boost::move(v));
|
||||||
constructor.construct_value2(boost::move(v));
|
|
||||||
return constructor.release();
|
return constructor.release();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -349,9 +349,7 @@ namespace boost { namespace unordered { namespace detail {
|
|||||||
// Create the node before rehashing in case it throws an
|
// Create the node before rehashing in case it throws an
|
||||||
// exception (need strong safety in such a case).
|
// exception (need strong safety in such a case).
|
||||||
node_constructor a(this->node_alloc());
|
node_constructor a(this->node_alloc());
|
||||||
a.construct_node();
|
a.construct_with_value(BOOST_UNORDERED_EMPLACE_ARGS3(
|
||||||
|
|
||||||
a.construct_value(BOOST_UNORDERED_EMPLACE_ARGS3(
|
|
||||||
boost::unordered::piecewise_construct,
|
boost::unordered::piecewise_construct,
|
||||||
boost::make_tuple(k),
|
boost::make_tuple(k),
|
||||||
boost::make_tuple()));
|
boost::make_tuple()));
|
||||||
@ -413,8 +411,7 @@ namespace boost { namespace unordered { namespace detail {
|
|||||||
// Create the node before rehashing in case it throws an
|
// Create the node before rehashing in case it throws an
|
||||||
// exception (need strong safety in such a case).
|
// exception (need strong safety in such a case).
|
||||||
node_constructor a(this->node_alloc());
|
node_constructor a(this->node_alloc());
|
||||||
a.construct_node();
|
a.construct_with_value(BOOST_UNORDERED_EMPLACE_FORWARD);
|
||||||
a.construct_value(BOOST_UNORDERED_EMPLACE_FORWARD);
|
|
||||||
|
|
||||||
// reserve has basic exception safety if the hash function
|
// reserve has basic exception safety if the hash function
|
||||||
// throws, strong otherwise.
|
// 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
|
// Don't have a key, so construct the node first in order
|
||||||
// to be able to lookup the position.
|
// to be able to lookup the position.
|
||||||
node_constructor a(this->node_alloc());
|
node_constructor a(this->node_alloc());
|
||||||
a.construct_node();
|
a.construct_with_value(BOOST_UNORDERED_EMPLACE_FORWARD);
|
||||||
a.construct_value(BOOST_UNORDERED_EMPLACE_FORWARD);
|
|
||||||
return emplace_impl_with_node(a);
|
return emplace_impl_with_node(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -490,8 +486,7 @@ namespace boost { namespace unordered { namespace detail {
|
|||||||
InputIt i, InputIt j)
|
InputIt i, InputIt j)
|
||||||
{
|
{
|
||||||
std::size_t key_hash = this->hash(k);
|
std::size_t key_hash = this->hash(k);
|
||||||
a.construct_node();
|
a.construct_with_value2(*i);
|
||||||
a.construct_value2(*i);
|
|
||||||
this->reserve_for_insert(this->size_ +
|
this->reserve_for_insert(this->size_ +
|
||||||
boost::unordered::detail::insert_size(i, j));
|
boost::unordered::detail::insert_size(i, j));
|
||||||
this->add_node(a, key_hash);
|
this->add_node(a, key_hash);
|
||||||
@ -506,9 +501,7 @@ namespace boost { namespace unordered { namespace detail {
|
|||||||
iterator pos = this->find_node(key_hash, k);
|
iterator pos = this->find_node(key_hash, k);
|
||||||
|
|
||||||
if (!pos.node_) {
|
if (!pos.node_) {
|
||||||
a.construct_node();
|
a.construct_with_value2(*i);
|
||||||
a.construct_value2(*i);
|
|
||||||
|
|
||||||
if(this->size_ + 1 > this->max_load_)
|
if(this->size_ + 1 > this->max_load_)
|
||||||
this->reserve_for_insert(this->size_ +
|
this->reserve_for_insert(this->size_ +
|
||||||
boost::unordered::detail::insert_size(i, j));
|
boost::unordered::detail::insert_size(i, j));
|
||||||
@ -524,8 +517,7 @@ namespace boost { namespace unordered { namespace detail {
|
|||||||
node_constructor a(this->node_alloc());
|
node_constructor a(this->node_alloc());
|
||||||
|
|
||||||
do {
|
do {
|
||||||
a.construct_node();
|
a.construct_with_value2(*i);
|
||||||
a.construct_value2(*i);
|
|
||||||
emplace_impl_with_node(a);
|
emplace_impl_with_node(a);
|
||||||
} while(++i != j);
|
} while(++i != j);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user