This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[v3] Small opt to alloc comparison in list
- From: Paolo Carlini <pcarlini at suse dot de>
- To: Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 18 Oct 2007 21:34:05 +0200
- Subject: [v3] Small opt to alloc comparison in list
Hi,
noticed while fixing 33807 (besides the opt issue, consistently with
swap, the present change would also orthogonally fix 33807).
Tested x86_64-linux, committed to mainline.
Paolo.
///////////////
2007-10-18 Paolo Carlini <pcarlini@suse.de>
* include/bits/allocator.h (struct __alloc_neq): Add.
* include/bits/stl_list.h (list<>::_M_check_equal_allocators): Use it.
Index: include/bits/stl_list.h
===================================================================
--- include/bits/stl_list.h (revision 129454)
+++ include/bits/stl_list.h (working copy)
@@ -1272,7 +1272,8 @@
void
_M_check_equal_allocators(list& __x)
{
- if (_M_get_Node_allocator() != __x._M_get_Node_allocator())
+ if (std::__alloc_neq<typename _Base::_Node_alloc_type>::
+ _S_do_it(_M_get_Node_allocator(), __x._M_get_Node_allocator()))
__throw_runtime_error(__N("list::_M_check_equal_allocators"));
}
};
Index: include/bits/allocator.h
===================================================================
--- include/bits/allocator.h (revision 129454)
+++ include/bits/allocator.h (working copy)
@@ -156,6 +156,23 @@
}
};
+ // Optimize for stateless allocators.
+ template<typename _Alloc, bool = __is_empty(_Alloc)>
+ struct __alloc_neq
+ {
+ static bool
+ _S_do_it(const _Alloc&, const _Alloc&)
+ { return false; }
+ };
+
+ template<typename _Alloc>
+ struct __alloc_neq<_Alloc, false>
+ {
+ static bool
+ _S_do_it(const _Alloc& __one, const _Alloc& __two)
+ { return __one != __two; }
+ };
+
_GLIBCXX_END_NAMESPACE
#endif