libstdc++: Optimize container node-handle type for size
authorJonathan Wakely <jwakely@redhat.com>
Mon, 19 Oct 2020 16:56:54 +0000 (17:56 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 19 Oct 2020 17:06:51 +0000 (18:06 +0100)
commitaa6d2be1e3455a5f0818d5bd6a44b15a55a39df5
treec8a40f330e254694f872eb33da58e496626c1d26
parent5abe05b4331250b6a7798ce87c0a82adc2bd70f3
libstdc++: Optimize container node-handle type for size

The use of std::optional in _Node_handle makes the node handle types for
associative and unordered containers larger than necessary. It also
greatly increases the amount of code included, as <optional> is quite
large.

The boolean flag that records whether the std::optional contains a value
is redundant, because the _Node_handle::_M_ptr member provides the same
information. If the node handle has a non-null pointer it also has an
allocator, and not otherwise. By replacing std::optional with a custom
union type (and using _M_ptr to tell which union member is active) all
node handle sizes can be reduced by sizeof(allocator_type::pointer).

This makes the node handle types incompatible with previous releases, so
must be done before the C++17 ABI is fixed for GCC 11.

libstdc++-v3/ChangeLog:

* include/bits/node_handle.h (_Node_handle_common): Replace
std::optional with custom type.
* testsuite/20_util/variant/exception_safety.cc: Add missing
header include.
libstdc++-v3/include/bits/node_handle.h
libstdc++-v3/testsuite/20_util/variant/exception_safety.cc