Commit f431d7ca by François Dumont

unordered_set: Minor formatting changes.

2011-12-12  François Dumont <fdumont@gcc.gnu.org>

	* include/profile/unordered_set: Minor formatting changes.
	(unordered_set<>::_M_profile_destruct,
	unordered_multiset<>::_M_profile_destruct): Fix implementation to not
	rely on normal implementation details anymore.
	(unordered_set<>::_M_profile_resize,
	unordered_multiset<>::_M_profile_resize): Implement consistently
	accross all unordered containers.
	(unordered_set<>::emplace, unordered_set<>::emplace_hint,
	unordered_multiset<>::emplace, unordered_multset<>::emplace_hint): Add
	to signal rehash to profiling system.
	* include/profile/unordered_map: Likewise for unordered_map<> and
	unordered_multimap<>.

From-SVN: r182188
parent 188b7e23
2011-12-12 François Dumont <fdumont@gcc.gnu.org>
* include/profile/unordered_set: Minor formatting changes.
(unordered_set<>::_M_profile_destruct,
unordered_multiset<>::_M_profile_destruct): Fix implementation to not
rely on normal implementation details anymore.
(unordered_set<>::_M_profile_resize,
unordered_multiset<>::_M_profile_resize): Implement consistently
accross all unordered containers.
(unordered_set<>::emplace, unordered_set<>::emplace_hint,
unordered_multiset<>::emplace, unordered_multset<>::emplace_hint): Add
to signal rehash to profiling system.
* include/profile/unordered_map: Likewise for unordered_map<> and
unordered_multimap<>.
2011-12-09 François Dumont <fdumont@gcc.gnu.org> 2011-12-09 François Dumont <fdumont@gcc.gnu.org>
* include/bits/hashtable.h (_Hashtable<>::emplace, * include/bits/hashtable.h (_Hashtable<>::emplace,
......
...@@ -171,6 +171,28 @@ namespace __profile ...@@ -171,6 +171,28 @@ namespace __profile
_Base::clear(); _Base::clear();
} }
template<typename... _Args>
std::pair<iterator, bool>
emplace(_Args&&... __args)
{
size_type __old_size = _Base::bucket_count();
std::pair<iterator, bool> __res
= _Base::emplace(std::forward<_Args>(__args)...);
_M_profile_resize(__old_size);
return __res;
}
template<typename... _Args>
iterator
emplace_hint(const_iterator __it, _Args&&... __args)
{
size_type __old_size = _Base::bucket_count();
iterator __res
= _Base::emplace_hint(__it, std::forward<_Args>(__args)...);
_M_profile_resize(__old_size);
return __res;
}
void void
insert(std::initializer_list<value_type> __l) insert(std::initializer_list<value_type> __l)
{ {
...@@ -282,14 +304,14 @@ namespace __profile ...@@ -282,14 +304,14 @@ namespace __profile
_M_profile_destruct() _M_profile_destruct()
{ {
size_type __hops = 0, __lc = 0, __chain = 0; size_type __hops = 0, __lc = 0, __chain = 0;
for (iterator __it = _M_base().begin(); __it != _M_base().end(); iterator __it = this->begin();
++__it) while (__it != this->end())
{
while (__it._M_cur_node->_M_next)
{ {
size_type __bkt = this->bucket(__it->first);
for (++__it; __it != this->end()
&& this->bucket(__it->first) == __bkt;
++__it)
++__chain; ++__chain;
++__it;
}
if (__chain) if (__chain)
{ {
++__chain; ++__chain;
...@@ -429,12 +451,6 @@ namespace __profile ...@@ -429,12 +451,6 @@ namespace __profile
_M_profile_destruct(); _M_profile_destruct();
} }
_Base&
_M_base() noexcept { return *this; }
const _Base&
_M_base() const noexcept { return *this; }
void void
clear() noexcept clear() noexcept
{ {
...@@ -444,12 +460,34 @@ namespace __profile ...@@ -444,12 +460,34 @@ namespace __profile
_Base::clear(); _Base::clear();
} }
template<typename... _Args>
iterator
emplace(_Args&&... __args)
{
size_type __old_size = _Base::bucket_count();
iterator __res
= _Base::emplace(std::forward<_Args>(__args)...);
_M_profile_resize(__old_size);
return __res;
}
template<typename... _Args>
iterator
emplace_hint(const_iterator __it, _Args&&... __args)
{
size_type __old_size = _Base::bucket_count();
iterator __res
= _Base::emplace_hint(__it, std::forward<_Args>(__args)...);
_M_profile_resize(__old_size);
return __res;
}
void void
insert(std::initializer_list<value_type> __l) insert(std::initializer_list<value_type> __l)
{ {
size_type __old_size = _Base::bucket_count(); size_type __old_size = _Base::bucket_count();
_Base::insert(__l); _Base::insert(__l);
_M_profile_resize(__old_size, _Base::bucket_count()); _M_profile_resize(__old_size);
} }
iterator iterator
...@@ -457,7 +495,7 @@ namespace __profile ...@@ -457,7 +495,7 @@ namespace __profile
{ {
size_type __old_size = _Base::bucket_count(); size_type __old_size = _Base::bucket_count();
iterator __res = _Base::insert(__obj); iterator __res = _Base::insert(__obj);
_M_profile_resize(__old_size, _Base::bucket_count()); _M_profile_resize(__old_size);
return __res; return __res;
} }
...@@ -466,7 +504,7 @@ namespace __profile ...@@ -466,7 +504,7 @@ namespace __profile
{ {
size_type __old_size = _Base::bucket_count(); size_type __old_size = _Base::bucket_count();
iterator __res = _Base::insert(__iter, __v); iterator __res = _Base::insert(__iter, __v);
_M_profile_resize(__old_size, _Base::bucket_count()); _M_profile_resize(__old_size);
return __res; return __res;
} }
...@@ -478,7 +516,7 @@ namespace __profile ...@@ -478,7 +516,7 @@ namespace __profile
{ {
size_type __old_size = _Base::bucket_count(); size_type __old_size = _Base::bucket_count();
iterator __res = _Base::insert(std::forward<_Pair>(__obj)); iterator __res = _Base::insert(std::forward<_Pair>(__obj));
_M_profile_resize(__old_size, _Base::bucket_count()); _M_profile_resize(__old_size);
return __res; return __res;
} }
...@@ -490,7 +528,7 @@ namespace __profile ...@@ -490,7 +528,7 @@ namespace __profile
{ {
size_type __old_size = _Base::bucket_count(); size_type __old_size = _Base::bucket_count();
iterator __res = _Base::insert(__iter, std::forward<_Pair>(__v)); iterator __res = _Base::insert(__iter, std::forward<_Pair>(__v));
_M_profile_resize(__old_size, _Base::bucket_count()); _M_profile_resize(__old_size);
return __res; return __res;
} }
...@@ -500,7 +538,7 @@ namespace __profile ...@@ -500,7 +538,7 @@ namespace __profile
{ {
size_type __old_size = _Base::bucket_count(); size_type __old_size = _Base::bucket_count();
_Base::insert(__first, __last); _Base::insert(__first, __last);
_M_profile_resize(__old_size, _Base::bucket_count()); _M_profile_resize(__old_size);
} }
void void
...@@ -508,7 +546,7 @@ namespace __profile ...@@ -508,7 +546,7 @@ namespace __profile
{ {
size_type __old_size = _Base::bucket_count(); size_type __old_size = _Base::bucket_count();
_Base::insert(__first, __last); _Base::insert(__first, __last);
_M_profile_resize(__old_size, _Base::bucket_count()); _M_profile_resize(__old_size);
} }
void void
...@@ -519,13 +557,14 @@ namespace __profile ...@@ -519,13 +557,14 @@ namespace __profile
{ {
size_type __old_size = _Base::bucket_count(); size_type __old_size = _Base::bucket_count();
_Base::rehash(__n); _Base::rehash(__n);
_M_profile_resize(__old_size, _Base::bucket_count()); _M_profile_resize(__old_size);
} }
private: private:
void void
_M_profile_resize(size_type __old_size, size_type __new_size) _M_profile_resize(size_type __old_size)
{ {
size_type __new_size = _Base::bucket_count();
if (__old_size != __new_size) if (__old_size != __new_size)
__profcxx_hashtable_resize(this, __old_size, __new_size); __profcxx_hashtable_resize(this, __old_size, __new_size);
} }
...@@ -534,14 +573,14 @@ namespace __profile ...@@ -534,14 +573,14 @@ namespace __profile
_M_profile_destruct() _M_profile_destruct()
{ {
size_type __hops = 0, __lc = 0, __chain = 0; size_type __hops = 0, __lc = 0, __chain = 0;
for (iterator __it = _M_base().begin(); __it != _M_base().end(); iterator __it = this->begin();
++__it) while (__it != this->end())
{
while (__it._M_cur_node->_M_next)
{ {
size_type __bkt = this->bucket(__it->first);
for (++__it; __it != this->end()
&& this->bucket(__it->first) == __bkt;
++__it)
++__chain; ++__chain;
++__it;
}
if (__chain) if (__chain)
{ {
++__chain; ++__chain;
...@@ -552,7 +591,6 @@ namespace __profile ...@@ -552,7 +591,6 @@ namespace __profile
} }
__profcxx_hashtable_destruct2(this, __lc, _Base::size(), __hops); __profcxx_hashtable_destruct2(this, __lc, _Base::size(), __hops);
} }
}; };
template<typename _Key, typename _Tp, typename _Hash, template<typename _Key, typename _Tp, typename _Hash,
......
...@@ -170,12 +170,34 @@ namespace __profile ...@@ -170,12 +170,34 @@ namespace __profile
_Base::clear(); _Base::clear();
} }
template<typename... _Args>
std::pair<iterator, bool>
emplace(_Args&&... __args)
{
size_type __old_size = _Base::bucket_count();
std::pair<iterator, bool> __res
= _Base::emplace(std::forward<_Args>(__args)...);
_M_profile_resize(__old_size);
return __res;
}
template<typename... _Args>
iterator
emplace_hint(const_iterator __it, _Args&&... __args)
{
size_type __old_size = _Base::bucket_count();
iterator __res
= _Base::emplace_hint(__it, std::forward<_Args>(__args)...);
_M_profile_resize(__old_size);
return __res;
}
void void
insert(std::initializer_list<value_type> __l) insert(std::initializer_list<value_type> __l)
{ {
size_type __old_size = _Base::bucket_count(); size_type __old_size = _Base::bucket_count();
_Base::insert(__l); _Base::insert(__l);
_M_profile_resize(__old_size, _Base::bucket_count()); _M_profile_resize(__old_size);
} }
std::pair<iterator, bool> std::pair<iterator, bool>
...@@ -183,7 +205,7 @@ namespace __profile ...@@ -183,7 +205,7 @@ namespace __profile
{ {
size_type __old_size = _Base::bucket_count(); size_type __old_size = _Base::bucket_count();
std::pair<iterator, bool> __res = _Base::insert(__obj); std::pair<iterator, bool> __res = _Base::insert(__obj);
_M_profile_resize(__old_size, _Base::bucket_count()); _M_profile_resize(__old_size);
return __res; return __res;
} }
...@@ -192,7 +214,7 @@ namespace __profile ...@@ -192,7 +214,7 @@ namespace __profile
{ {
size_type __old_size = _Base::bucket_count(); size_type __old_size = _Base::bucket_count();
iterator __res = _Base::insert(__iter, __v); iterator __res = _Base::insert(__iter, __v);
_M_profile_resize(__old_size, _Base::bucket_count()); _M_profile_resize(__old_size);
return __res; return __res;
} }
...@@ -201,7 +223,7 @@ namespace __profile ...@@ -201,7 +223,7 @@ namespace __profile
{ {
size_type __old_size = _Base::bucket_count(); size_type __old_size = _Base::bucket_count();
std::pair<iterator, bool> __res = _Base::insert(std::move(__obj)); std::pair<iterator, bool> __res = _Base::insert(std::move(__obj));
_M_profile_resize(__old_size, _Base::bucket_count()); _M_profile_resize(__old_size);
return __res; return __res;
} }
...@@ -210,7 +232,7 @@ namespace __profile ...@@ -210,7 +232,7 @@ namespace __profile
{ {
size_type __old_size = _Base::bucket_count(); size_type __old_size = _Base::bucket_count();
iterator __res = _Base::insert(__iter, std::move(__v)); iterator __res = _Base::insert(__iter, std::move(__v));
_M_profile_resize(__old_size, _Base::bucket_count()); _M_profile_resize(__old_size);
return __res; return __res;
} }
...@@ -220,7 +242,7 @@ namespace __profile ...@@ -220,7 +242,7 @@ namespace __profile
{ {
size_type __old_size = _Base::bucket_count(); size_type __old_size = _Base::bucket_count();
_Base::insert(__first, __last); _Base::insert(__first, __last);
_M_profile_resize(__old_size, _Base::bucket_count()); _M_profile_resize(__old_size);
} }
void void
...@@ -228,26 +250,21 @@ namespace __profile ...@@ -228,26 +250,21 @@ namespace __profile
{ {
size_type __old_size = _Base::bucket_count(); size_type __old_size = _Base::bucket_count();
_Base::insert(__first, __last); _Base::insert(__first, __last);
_M_profile_resize(__old_size, _Base::bucket_count()); _M_profile_resize(__old_size);
} }
void rehash(size_type __n) void rehash(size_type __n)
{ {
size_type __old_size = _Base::bucket_count(); size_type __old_size = _Base::bucket_count();
_Base::rehash(__n); _Base::rehash(__n);
_M_profile_resize(__old_size, _Base::bucket_count()); _M_profile_resize(__old_size);
} }
private: private:
_Base&
_M_base() noexcept { return *this; }
const _Base&
_M_base() const noexcept { return *this; }
void void
_M_profile_resize(size_type __old_size, size_type __new_size) _M_profile_resize(size_type __old_size)
{ {
size_type __new_size = _Base::bucket_count();
if (__old_size != __new_size) if (__old_size != __new_size)
__profcxx_hashtable_resize(this, __old_size, __new_size); __profcxx_hashtable_resize(this, __old_size, __new_size);
} }
...@@ -256,14 +273,13 @@ namespace __profile ...@@ -256,14 +273,13 @@ namespace __profile
_M_profile_destruct() _M_profile_destruct()
{ {
size_type __hops = 0, __lc = 0, __chain = 0; size_type __hops = 0, __lc = 0, __chain = 0;
for (iterator __it = _M_base().begin(); __it != _M_base().end(); iterator __it = this->begin();
++__it) while (__it != this->end())
{
while (__it._M_cur_node->_M_next)
{ {
size_type __bkt = this->bucket(*__it);
for (++__it; __it != this->end() && this->bucket(*__it) == __bkt;
++__it)
++__chain; ++__chain;
++__it;
}
if (__chain) if (__chain)
{ {
...@@ -275,7 +291,6 @@ namespace __profile ...@@ -275,7 +291,6 @@ namespace __profile
} }
__profcxx_hashtable_destruct2(this, __lc, _Base::size(), __hops); __profcxx_hashtable_destruct2(this, __lc, _Base::size(), __hops);
} }
}; };
template<typename _Value, typename _Hash, typename _Pred, typename _Alloc> template<typename _Value, typename _Hash, typename _Pred, typename _Alloc>
...@@ -418,12 +433,33 @@ namespace __profile ...@@ -418,12 +433,33 @@ namespace __profile
_Base::clear(); _Base::clear();
} }
template<typename... _Args>
iterator
emplace(_Args&&... __args)
{
size_type __old_size = _Base::bucket_count();
iterator __res = _Base::emplace(std::forward<_Args>(__args)...);
_M_profile_resize(__old_size);
return __res;
}
template<typename... _Args>
iterator
emplace_hint(const_iterator __it, _Args&&... __args)
{
size_type __old_size = _Base::bucket_count();
iterator __res
= _Base::emplace_hint(__it, std::forward<_Args>(__args)...);
_M_profile_resize(__old_size);
return __res;
}
void void
insert(std::initializer_list<value_type> __l) insert(std::initializer_list<value_type> __l)
{ {
size_type __old_size = _Base::bucket_count(); size_type __old_size = _Base::bucket_count();
_Base::insert(__l); _Base::insert(__l);
_M_profile_resize(__old_size, _Base::bucket_count()); _M_profile_resize(__old_size);
} }
iterator iterator
...@@ -431,7 +467,7 @@ namespace __profile ...@@ -431,7 +467,7 @@ namespace __profile
{ {
size_type __old_size = _Base::bucket_count(); size_type __old_size = _Base::bucket_count();
iterator __res = _Base::insert(__obj); iterator __res = _Base::insert(__obj);
_M_profile_resize(__old_size, _Base::bucket_count()); _M_profile_resize(__old_size);
return __res; return __res;
} }
...@@ -440,7 +476,7 @@ namespace __profile ...@@ -440,7 +476,7 @@ namespace __profile
{ {
size_type __old_size = _Base::bucket_count(); size_type __old_size = _Base::bucket_count();
iterator __res = _Base::insert(__iter, __v); iterator __res = _Base::insert(__iter, __v);
_M_profile_resize(__old_size, _Base::bucket_count()); _M_profile_resize(__old_size);
return __res; return __res;
} }
...@@ -449,7 +485,7 @@ namespace __profile ...@@ -449,7 +485,7 @@ namespace __profile
{ {
size_type __old_size = _Base::bucket_count(); size_type __old_size = _Base::bucket_count();
iterator __res = _Base::insert(std::move(__obj)); iterator __res = _Base::insert(std::move(__obj));
_M_profile_resize(__old_size, _Base::bucket_count()); _M_profile_resize(__old_size);
return __res; return __res;
} }
...@@ -458,7 +494,7 @@ namespace __profile ...@@ -458,7 +494,7 @@ namespace __profile
{ {
size_type __old_size = _Base::bucket_count(); size_type __old_size = _Base::bucket_count();
iterator __res = _Base::insert(__iter, std::move(__v)); iterator __res = _Base::insert(__iter, std::move(__v));
_M_profile_resize(__old_size, _Base::bucket_count()); _M_profile_resize(__old_size);
return __res; return __res;
} }
...@@ -468,7 +504,7 @@ namespace __profile ...@@ -468,7 +504,7 @@ namespace __profile
{ {
size_type __old_size = _Base::bucket_count(); size_type __old_size = _Base::bucket_count();
_Base::insert(__first, __last); _Base::insert(__first, __last);
_M_profile_resize(__old_size, _Base::bucket_count()); _M_profile_resize(__old_size);
} }
void void
...@@ -476,26 +512,21 @@ namespace __profile ...@@ -476,26 +512,21 @@ namespace __profile
{ {
size_type __old_size = _Base::bucket_count(); size_type __old_size = _Base::bucket_count();
_Base::insert(__first, __last); _Base::insert(__first, __last);
_M_profile_resize(__old_size, _Base::bucket_count()); _M_profile_resize(__old_size);
} }
void rehash(size_type __n) void rehash(size_type __n)
{ {
size_type __old_size = _Base::bucket_count(); size_type __old_size = _Base::bucket_count();
_Base::rehash(__n); _Base::rehash(__n);
_M_profile_resize(__old_size, _Base::bucket_count()); _M_profile_resize(__old_size);
} }
private: private:
_Base&
_M_base() noexcept { return *this; }
const _Base&
_M_base() const noexcept { return *this; }
void void
_M_profile_resize(size_type __old_size, size_type __new_size) _M_profile_resize(size_type __old_size)
{ {
size_type __new_size = _Base::bucket_count();
if (__old_size != __new_size) if (__old_size != __new_size)
__profcxx_hashtable_resize(this, __old_size, __new_size); __profcxx_hashtable_resize(this, __old_size, __new_size);
} }
...@@ -504,14 +535,13 @@ namespace __profile ...@@ -504,14 +535,13 @@ namespace __profile
_M_profile_destruct() _M_profile_destruct()
{ {
size_type __hops = 0, __lc = 0, __chain = 0; size_type __hops = 0, __lc = 0, __chain = 0;
for (iterator __it = _M_base().begin(); __it != _M_base().end(); iterator __it = this->begin();
++__it) while (__it != this->end())
{
while (__it._M_cur_node->_M_next)
{ {
size_type __bkt = this->bucket(*__it);
for (++__it; __it != this->end() && this->bucket(*__it) == __bkt;
++__it)
++__chain; ++__chain;
++__it;
}
if (__chain) if (__chain)
{ {
...@@ -523,7 +553,6 @@ namespace __profile ...@@ -523,7 +553,6 @@ namespace __profile
} }
__profcxx_hashtable_destruct2(this, __lc, _Base::size(), __hops); __profcxx_hashtable_destruct2(this, __lc, _Base::size(), __hops);
} }
}; };
template<typename _Value, typename _Hash, typename _Pred, typename _Alloc> template<typename _Value, typename _Hash, typename _Pred, typename _Alloc>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment