summaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/bits
diff options
context:
space:
mode:
authorbstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4>2012-01-20 09:01:05 +0000
committerbstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4>2012-01-20 09:01:05 +0000
commitad046ecfafd816611ab5ecdb1319e052f425c50e (patch)
tree4875c49c0290393fc8a599cef2d366da0599caab /libstdc++-v3/include/bits
parent4aa8e549a47056781bea0481347468e8f9367a3a (diff)
downloadgcc-ad046ecfafd816611ab5ecdb1319e052f425c50e.tar.gz
2012-01-20 Basile Starynkevitch <basile@starynkevitch.net>
MELT branch merged with trunk rev 183326 using svnmerge git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/melt-branch@183327 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/bits')
-rw-r--r--libstdc++-v3/include/bits/hashtable.h21
1 files changed, 12 insertions, 9 deletions
diff --git a/libstdc++-v3/include/bits/hashtable.h b/libstdc++-v3/include/bits/hashtable.h
index 37672a26b6f..d4f2aedfccd 100644
--- a/libstdc++-v3/include/bits/hashtable.h
+++ b/libstdc++-v3/include/bits/hashtable.h
@@ -1227,7 +1227,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
= this->_M_hash_code(__k);
this->_M_store_code(__new_node, __code);
- // Second, do rehash if necessary.
+ // Second, do rehash if necessary.
if (__do_rehash.first)
_M_rehash(__do_rehash.second, __saved_state);
@@ -1347,21 +1347,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
= _M_rehash_policy._M_need_rehash(_M_bucket_count,
_M_element_count, 1);
- const key_type& __k = this->_M_extract()(__v);
- typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k);
+ // First compute the hash code so that we don't do anything if it throws.
+ typename _Hashtable::_Hash_code_type __code
+ = this->_M_hash_code(this->_M_extract()(__v));
_Node* __new_node = nullptr;
__try
{
- // First allocate new node so that we don't rehash if it throws.
+ // Second allocate new node so that we don't rehash if it throws.
__new_node = _M_allocate_node(std::forward<_Arg>(__v));
this->_M_store_code(__new_node, __code);
if (__do_rehash.first)
_M_rehash(__do_rehash.second, __saved_state);
- // Second, find the node before an equivalent one.
- size_type __n = _M_bucket_index(__k, __code);
- _BaseNode* __prev = _M_find_before_node(__n, __k, __code);
+ // Third, find the node before an equivalent one.
+ size_type __bkt = _M_bucket_index(__new_node);
+ _BaseNode* __prev
+ = _M_find_before_node(__bkt, this->_M_extract()(__new_node->_M_v),
+ __code);
if (__prev)
{
// Insert after the node before the equivalent one.
@@ -1372,7 +1375,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// The inserted node has no equivalent in the hashtable. We must
// insert the new node at the beginning of the bucket to preserve
// equivalent elements relative positions.
- _M_insert_bucket_begin(__n, __new_node);
+ _M_insert_bucket_begin(__bkt, __new_node);
++_M_element_count;
return iterator(__new_node);
}
@@ -1541,7 +1544,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__bkt = __n_bkt;
}
- if (__n && __n_bkt != __bkt)
+ if (__n && (__n_bkt != __bkt || __is_bucket_begin))
_M_buckets[__n_bkt] = __prev_n;
__prev_n->_M_nxt = __n;
return iterator(__n);