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)
{ {
...@@ -182,7 +204,7 @@ namespace __profile ...@@ -182,7 +204,7 @@ namespace __profile
std::pair<iterator, bool> std::pair<iterator, bool>
insert(const value_type& __obj) insert(const value_type& __obj)
{ {
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); _M_profile_resize(__old_size);
return __res; return __res;
...@@ -203,7 +225,7 @@ namespace __profile ...@@ -203,7 +225,7 @@ namespace __profile
std::pair<iterator, bool> std::pair<iterator, bool>
insert(_Pair&& __obj) insert(_Pair&& __obj)
{ {
size_type __old_size = _Base::bucket_count(); size_type __old_size = _Base::bucket_count();
std::pair<iterator, bool> __res std::pair<iterator, bool> __res
= _Base::insert(std::forward<_Pair>(__obj)); = _Base::insert(std::forward<_Pair>(__obj));
_M_profile_resize(__old_size); _M_profile_resize(__old_size);
...@@ -243,7 +265,7 @@ namespace __profile ...@@ -243,7 +265,7 @@ namespace __profile
mapped_type& mapped_type&
operator[](const _Key& __k) operator[](const _Key& __k)
{ {
size_type __old_size = _Base::bucket_count(); size_type __old_size = _Base::bucket_count();
mapped_type& __res = _M_base()[__k]; mapped_type& __res = _M_base()[__k];
_M_profile_resize(__old_size); _M_profile_resize(__old_size);
return __res; return __res;
...@@ -252,7 +274,7 @@ namespace __profile ...@@ -252,7 +274,7 @@ namespace __profile
mapped_type& mapped_type&
operator[](_Key&& __k) operator[](_Key&& __k)
{ {
size_type __old_size = _Base::bucket_count(); size_type __old_size = _Base::bucket_count();
mapped_type& __res = _M_base()[std::move(__k)]; mapped_type& __res = _M_base()[std::move(__k)];
_M_profile_resize(__old_size); _M_profile_resize(__old_size);
return __res; return __res;
...@@ -264,9 +286,9 @@ namespace __profile ...@@ -264,9 +286,9 @@ namespace __profile
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); _M_profile_resize(__old_size);
} }
private: private:
...@@ -274,33 +296,33 @@ namespace __profile ...@@ -274,33 +296,33 @@ namespace __profile
_M_profile_resize(size_type __old_size) _M_profile_resize(size_type __old_size)
{ {
size_type __new_size = _Base::bucket_count(); 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);
} }
void void
_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()
++__chain; && this->bucket(__it->first) == __bkt;
++__it; ++__it)
} ++__chain;
if (__chain) if (__chain)
{ {
++__chain; ++__chain;
__lc = __lc > __chain ? __lc : __chain; __lc = __lc > __chain ? __lc : __chain;
__hops += __chain * (__chain - 1) / 2; __hops += __chain * (__chain - 1) / 2;
__chain = 0; __chain = 0;
} }
} }
__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,
typename _Pred, typename _Alloc> typename _Pred, typename _Alloc>
...@@ -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,20 +460,42 @@ namespace __profile ...@@ -444,20 +460,42 @@ 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
insert(const value_type& __obj) insert(const value_type& __obj)
{ {
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;
} }
...@@ -476,9 +514,9 @@ namespace __profile ...@@ -476,9 +514,9 @@ namespace __profile
iterator iterator
insert(_Pair&& __obj) insert(_Pair&& __obj)
{ {
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
...@@ -517,15 +555,16 @@ namespace __profile ...@@ -517,15 +555,16 @@ namespace __profile
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:
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);
} }
...@@ -533,15 +572,15 @@ namespace __profile ...@@ -533,15 +572,15 @@ namespace __profile
void void
_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()
++__chain; && this->bucket(__it->first) == __bkt;
++__it; ++__it)
} ++__chain;
if (__chain) if (__chain)
{ {
++__chain; ++__chain;
...@@ -550,10 +589,9 @@ namespace __profile ...@@ -550,10 +589,9 @@ namespace __profile
__chain = 0; __chain = 0;
} }
} }
__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,
typename _Pred, typename _Alloc> typename _Pred, typename _Alloc>
......
...@@ -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,55 +250,48 @@ namespace __profile ...@@ -228,55 +250,48 @@ 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)
{ {
if (__old_size != __new_size) size_type __new_size = _Base::bucket_count();
if (__old_size != __new_size)
__profcxx_hashtable_resize(this, __old_size, __new_size); __profcxx_hashtable_resize(this, __old_size, __new_size);
} }
void void
_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)
{ {
++__chain; ++__chain;
__lc = __lc > __chain ? __lc : __chain; __lc = __lc > __chain ? __lc : __chain;
__hops += __chain * (__chain - 1) / 2; __hops += __chain * (__chain - 1) / 2;
__chain = 0; __chain = 0;
} }
} }
__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>
inline void inline void
...@@ -418,20 +433,41 @@ namespace __profile ...@@ -418,20 +433,41 @@ 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
insert(const value_type& __obj) insert(const value_type& __obj)
{ {
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,16 +476,16 @@ namespace __profile ...@@ -440,16 +476,16 @@ 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;
} }
iterator iterator
insert(value_type&& __obj) insert(value_type&& __obj)
{ {
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);
} }
...@@ -503,27 +534,25 @@ namespace __profile ...@@ -503,27 +534,25 @@ namespace __profile
void void
_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;
++__chain; ++__it)
++__it;
}
if (__chain)
{
++__chain; ++__chain;
__lc = __lc > __chain ? __lc : __chain;
__hops += __chain * (__chain - 1) / 2;
__chain = 0;
}
}
__profcxx_hashtable_destruct2(this, __lc, _Base::size(), __hops);
}
if (__chain)
{
++__chain;
__lc = __lc > __chain ? __lc : __chain;
__hops += __chain * (__chain - 1) / 2;
__chain = 0;
}
}
__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