Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

erase(iterator) perf #138

Merged
merged 2 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions include/boost/unordered/detail/implementation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2928,6 +2928,23 @@ namespace boost {
return 1;
}

iterator erase_node(c_iterator pos) {
c_iterator next = pos;
++next;

bucket_iterator itb = pos.itb;
node_pointer* pp = boost::addressof(itb->next);
while (*pp != pos.p) {
pp = boost::addressof((*pp)->next);
}

buckets_.extract_node_after(itb, pp);
this->delete_node(pos.p);
--size_;

return iterator(next.p, next.itb);
}

iterator erase_nodes_range(c_iterator first, c_iterator last)
{
if (first == last) {
Expand Down
16 changes: 4 additions & 12 deletions include/boost/unordered/unordered_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1856,18 +1856,14 @@ namespace boost {
typename unordered_map<K, T, H, P, A>::iterator
unordered_map<K, T, H, P, A>::erase(iterator position)
{
const_iterator last = position;
++last;
return table_.erase_nodes_range(position, last);
return table_.erase_node(position);
}

template <class K, class T, class H, class P, class A>
typename unordered_map<K, T, H, P, A>::iterator
unordered_map<K, T, H, P, A>::erase(const_iterator position)
{
const_iterator last = position;
++last;
return table_.erase_nodes_range(position, last);
return table_.erase_node(position);
}

template <class K, class T, class H, class P, class A>
Expand Down Expand Up @@ -2340,19 +2336,15 @@ namespace boost {
unordered_multimap<K, T, H, P, A>::erase(iterator position)
{
BOOST_ASSERT(position != this->end());
iterator next = position;
++next;
return table_.erase_nodes_range(position, next);
return table_.erase_node(position);
}

template <class K, class T, class H, class P, class A>
typename unordered_multimap<K, T, H, P, A>::iterator
unordered_multimap<K, T, H, P, A>::erase(const_iterator position)
{
BOOST_ASSERT(position != this->end());
const_iterator next = position;
++next;
return table_.erase_nodes_range(position, next);
return table_.erase_node(position);
}

template <class K, class T, class H, class P, class A>
Expand Down
9 changes: 2 additions & 7 deletions include/boost/unordered/unordered_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1457,9 +1457,7 @@ namespace boost {
typename unordered_set<T, H, P, A>::iterator
unordered_set<T, H, P, A>::erase(const_iterator position)
{
const_iterator last = position;
++last;
return table_.erase_nodes_range(position, last);
return table_.erase_node(position);
}

template <class T, class H, class P, class A>
Expand Down Expand Up @@ -1853,10 +1851,7 @@ namespace boost {
unordered_multiset<T, H, P, A>::erase(const_iterator position)
{
BOOST_ASSERT(position != this->end());
iterator next = position;
++next;
table_.erase_nodes_range(position, next);
return next;
return table_.erase_node(position);
}

template <class T, class H, class P, class A>
Expand Down