aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2019-05-16 21:30:27 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2019-05-16 21:30:27 +0100
commitb62dcd16aa033968075f19631c757bb39a16ef92 (patch)
tree93b75bd835ebd1d7f85113f2a4f6334b4d87f0de
parent5120e0d8d48f4590a275e60565de6c5a4e772fc1 (diff)
downloadgcc-b62dcd16aa033968075f19631c757bb39a16ef92.zip
gcc-b62dcd16aa033968075f19631c757bb39a16ef92.tar.gz
gcc-b62dcd16aa033968075f19631c757bb39a16ef92.tar.bz2
Changes to std::variant to reduce code size
* include/std/variant (_Variant_storage<false, _Types...>::_M_reset): Replace raw visitation with a runtime check for the valueless state and a non-raw visitor. (_Variant_storage<false, _Types...>::_M_reset_impl): Remove. (variant::index()): Remove branch. (variant::swap(variant&)): Use valueless_by_exception() instead of comparing the index to variant_npos, and add likelihood attribute. From-SVN: r271295
-rw-r--r--libstdc++-v3/ChangeLog8
-rw-r--r--libstdc++-v3/include/std/variant26
2 files changed, 17 insertions, 17 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 060d92a..997924e 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,13 @@
2019-05-16 Jonathan Wakely <jwakely@redhat.com>
+ * include/std/variant (_Variant_storage<false, _Types...>::_M_reset):
+ Replace raw visitation with a runtime check for the valueless state
+ and a non-raw visitor.
+ (_Variant_storage<false, _Types...>::_M_reset_impl): Remove.
+ (variant::index()): Remove branch.
+ (variant::swap(variant&)): Use valueless_by_exception() instead of
+ comparing the index to variant_npos, and add likelihood attribute.
+
* include/bits/hashtable_policy.h (_Equal_helper): Remove.
(_Hashtable_base::_Equal_hash_code): Define new class template.
(_Hashtable_base::_M_equals): Use _Equal_hash_code instead of
diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index 8c710c3..101b894 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -396,19 +396,16 @@ namespace __variant
_M_index(_Np)
{ }
- constexpr void _M_reset_impl()
+ void _M_reset()
{
- __variant::__raw_visit([](auto&& __this_mem) mutable
+ if (!_M_valid()) [[unlikely]]
+ return;
+
+ std::__do_visit<void>([](auto&& __this_mem) mutable
{
- if constexpr (!is_same_v<remove_reference_t<decltype(__this_mem)>,
- __variant_cookie>)
- std::_Destroy(std::__addressof(__this_mem));
+ std::_Destroy(std::__addressof(__this_mem));
}, __variant_cast<_Types...>(*this));
- }
- void _M_reset()
- {
- _M_reset_impl();
_M_index = variant_npos;
}
@@ -1485,12 +1482,7 @@ namespace __variant
{ return !this->_M_valid(); }
constexpr size_t index() const noexcept
- {
- if (this->_M_index ==
- typename _Base::__index_type(variant_npos))
- return variant_npos;
- return this->_M_index;
- }
+ { return size_t(typename _Base::__index_type(this->_M_index + 1)) - 1; }
void
swap(variant& __rhs)
@@ -1511,7 +1503,7 @@ namespace __variant
}
else
{
- if (this->index() != variant_npos)
+ if (!this->valueless_by_exception()) [[__likely__]]
{
auto __tmp(std::move(__rhs_mem));
__rhs = std::move(*this);
@@ -1528,7 +1520,7 @@ namespace __variant
}
else
{
- if (this->index() != variant_npos)
+ if (!this->valueless_by_exception()) [[__likely__]]
{
__rhs = std::move(*this);
this->_M_reset();