forked from boostorg/unordered
Fix exception safety in assignment for multimap/multiset.
The assignment code seemed like a bit of a premature optimization, I replaced it with a slightly slower but much simpler implementation.
This commit is contained in:
@@ -385,7 +385,14 @@ namespace boost { namespace unordered { namespace detail {
|
||||
std::size_t key_hash,
|
||||
iterator pos)
|
||||
{
|
||||
node_pointer n = a.release();
|
||||
return add_node(a.release(), key_hash, pos);
|
||||
}
|
||||
|
||||
inline iterator add_node(
|
||||
node_pointer n,
|
||||
std::size_t key_hash,
|
||||
iterator pos)
|
||||
{
|
||||
n->hash_ = key_hash;
|
||||
if (pos.node_) {
|
||||
this->add_after_node(n, pos.node_);
|
||||
@@ -622,30 +629,17 @@ namespace boost { namespace unordered { namespace detail {
|
||||
// fill_buckets
|
||||
|
||||
template <class NodeCreator>
|
||||
static void fill_buckets(iterator n, table& dst,
|
||||
NodeCreator& creator)
|
||||
void fill_buckets(iterator n, NodeCreator& creator)
|
||||
{
|
||||
link_pointer prev = dst.get_previous_start();
|
||||
|
||||
while (n.node_) {
|
||||
std::size_t key_hash = n.node_->hash_;
|
||||
iterator group_end(n.node_->group_prev_->next_);
|
||||
|
||||
node_pointer first_node = creator.create(*n);
|
||||
node_pointer end = first_node;
|
||||
first_node->hash_ = key_hash;
|
||||
prev->next_ = first_node;
|
||||
++dst.size_;
|
||||
|
||||
iterator pos = this->add_node(creator.create(*n), key_hash, iterator());
|
||||
for (++n; n != group_end; ++n)
|
||||
{
|
||||
end = creator.create(*n);
|
||||
end->hash_ = key_hash;
|
||||
add_after_node(end, first_node);
|
||||
++dst.size_;
|
||||
this->add_node(creator.create(*n), key_hash, pos);
|
||||
}
|
||||
|
||||
prev = place_in_bucket(dst, prev, end);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -393,7 +393,7 @@ namespace boost { namespace unordered { namespace detail {
|
||||
if (x.size_) {
|
||||
create_buckets(bucket_count_);
|
||||
copy_nodes<node_allocator> node_creator(node_alloc());
|
||||
table_impl::fill_buckets(x.begin(), *this, node_creator);
|
||||
static_cast<table_impl*>(this)->fill_buckets(x.begin(), node_creator);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -408,7 +408,7 @@ namespace boost { namespace unordered { namespace detail {
|
||||
|
||||
move_nodes<node_allocator> node_creator(node_alloc());
|
||||
node_holder<node_allocator> nodes(x);
|
||||
table_impl::fill_buckets(nodes.begin(), *this, node_creator);
|
||||
static_cast<table_impl*>(this)->fill_buckets(nodes.begin(), node_creator);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -654,7 +654,7 @@ namespace boost { namespace unordered { namespace detail {
|
||||
// assigning to them if possible, and deleting any that are
|
||||
// left over.
|
||||
assign_nodes<table> node_creator(*this);
|
||||
table_impl::fill_buckets(x.begin(), *this, node_creator);
|
||||
static_cast<table_impl*>(this)->fill_buckets(x.begin(), node_creator);
|
||||
}
|
||||
|
||||
void assign(table const& x, true_type)
|
||||
@@ -681,7 +681,7 @@ namespace boost { namespace unordered { namespace detail {
|
||||
if (x.size_) {
|
||||
create_buckets(bucket_count_);
|
||||
copy_nodes<node_allocator> node_creator(node_alloc());
|
||||
table_impl::fill_buckets(x.begin(), *this, node_creator);
|
||||
static_cast<table_impl*>(this)->fill_buckets(x.begin(), node_creator);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -740,7 +740,7 @@ namespace boost { namespace unordered { namespace detail {
|
||||
// any that are left over.
|
||||
move_assign_nodes<table> node_creator(*this);
|
||||
node_holder<node_allocator> nodes(x);
|
||||
table_impl::fill_buckets(nodes.begin(), *this, node_creator);
|
||||
static_cast<table_impl*>(this)->fill_buckets(nodes.begin(), node_creator);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -311,7 +311,13 @@ namespace boost { namespace unordered { namespace detail {
|
||||
node_constructor& a,
|
||||
std::size_t key_hash)
|
||||
{
|
||||
node_pointer n = a.release();
|
||||
return add_node(a.release(), key_hash);
|
||||
}
|
||||
|
||||
inline iterator add_node(
|
||||
node_pointer n,
|
||||
std::size_t key_hash)
|
||||
{
|
||||
n->hash_ = key_hash;
|
||||
|
||||
bucket_pointer b = this->get_bucket(this->hash_to_bucket(key_hash));
|
||||
@@ -577,19 +583,10 @@ namespace boost { namespace unordered { namespace detail {
|
||||
// fill_buckets
|
||||
|
||||
template <class NodeCreator>
|
||||
static void fill_buckets(iterator n, table& dst,
|
||||
NodeCreator& creator)
|
||||
void fill_buckets(iterator n, NodeCreator& creator)
|
||||
{
|
||||
link_pointer prev = dst.get_previous_start();
|
||||
|
||||
while (n.node_) {
|
||||
node_pointer node = creator.create(*n);
|
||||
node->hash_ = n.node_->hash_;
|
||||
prev->next_ = node;
|
||||
++dst.size_;
|
||||
++n;
|
||||
|
||||
prev = place_in_bucket(dst, prev);
|
||||
for (; n.node_; ++n) {
|
||||
this->add_node(creator.create(*n), n.node_->hash_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user