Skip to content
Snippets Groups Projects
Unverified Commit 689d4abc authored by Jonathan Wakely's avatar Jonathan Wakely Committed by Jonathan Wakely
Browse files

libstdc++: Further simplify _Hashtable inheritance hierarchy

The main change here is using [[no_unique_address]] instead of the Empty
Base-class Optimization. Using the attribute allows us to use data
members instead of base-classes. That simplifies the inheritance
hierarchy, which means less work for the compiler. It also means that
ADL has fewer associated classes and associated namespaces to consider,
further reducing the work the compiler has to do.

Reducing the differences between the _Hashtable_ebo_helper primary
template and the partial specialization means we no longer need to use
member functions to access the stored object, because it's now always a
data member called _M_obj.  This means we can also remove a number of
other helper functions that were using those member functions to access
the object, for example we can swap the _Hash and _Equal objects
directly in _Hashtable::swap instead of calling _Hashtable_base::_M_swap
which then calls _Hash_code_base::_M_swap.

Although [[no_unique_address]] would allow us to reduce the size for
empty types that are also 'final', doing so would be an ABI break
because those types were previously excluded from using the EBO. So we
still need the _Hashtable_ebo_helper class template and a partial
specialization, so that we only use the attribute under exactly the same
conditions as we previously used the EBO. This could be avoided with a
non-standard [[no_unique_address(expr)]] attribute that took a boolean
condition, or with reflection and token sequence injection, but we don't
have either of those things.

Because _Hashtable_ebo_helper is no longer used as a base-class we don't
need to disambiguate possible identical bases, so it doesn't need an
integral non-type template parameter.

libstdc++-v3/ChangeLog:

	* include/bits/hashtable.h (_Hashtable::swap): Swap hash
	function and equality predicate here. Inline allocator swap
	instead of using __alloc_on_swap.
	* include/bits/hashtable_policy.h (_Hashtable_ebo_helper):
	Replace EBO with no_unique_address attribute. Remove NTTP.
	(_Hash_code_base): Replace base class with data member using
	no_unique_address attribute.
	(_Hash_code_base::_M_swap): Remove.
	(_Hash_code_base::_M_hash): Remove.
	(_Hashtable_base): Replace base class with data member using
	no_unique_address attribute.
	(_Hashtable_base::_M_swap): Remove.
	(_Hashtable_alloc): Replace base class with data member using
	no_unique_address attribute.
parent 2ce99c00
No related branches found
No related tags found
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment