gcc/libstdc++-v3/include
Jonathan Wakely cfb582f627 libstdc++: Optimize std::visit for the common case [PR 78113]
GCC does not do a good job of optimizing the table of function pointers
used for variant visitation. This avoids using the table for the common
case of visiting a single variant with a small number of alternative
types. Instead we use:

  switch(v.index())
  {
  case 0: return visitor(get<0>(v));
  case 1: return visitor(get<1>(v));
  ...
  }

It's not quite that simple, because get<1>(v) is ill-formed if the
variant only has one alternative, and similarly for each get<N>.  We
need to ensure each case only applies the visitor if the index is in
range for the actual type we're dealing with, and tell the compiler that
the case is unreachable otherwise. We also need to invoke the visitor
via the __gen_vtable_impl::__visit_invoke function, to handle the raw
visitation cases used to implement std::variant assignments and
comparisons.

Because that gets quite verbose and repetitive, a macro is used to stamp
out the cases.

We also need to handle the valueless_by_exception case, but only for raw
visitation, because std::visit already checks for it before calling
__do_visit.

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>

libstdc++-v3/ChangeLog:

	PR libstdc++/78113
	* include/std/variant (__do_visit): Use a switch when we have a
	single variant with a small number of alternatives.
2021-10-01 20:34:48 +01:00
..
backward Update copyright years. 2021-01-04 10:26:59 +01:00
bits libstdc++: Simplify __normal_iterator converting constructor 2021-10-01 20:34:48 +01:00
c Update copyright years. 2021-01-04 10:26:59 +01:00
c_compatibility Update copyright years. 2021-01-04 10:26:59 +01:00
c_global libstdc++: Add additional overload of std::lerp [PR101870] 2021-08-12 19:46:16 +01:00
c_std Update copyright years. 2021-01-04 10:26:59 +01:00
debug libstdc++: Fix CTAD for debug sequence containers 2021-08-18 14:26:38 +01:00
decimal libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
experimental libstdc++: Add 'noexcept' to path::iterator members 2021-09-17 20:43:34 +01:00
ext libstdc++: Fix std::allocator<void> for versioned namespace 2021-08-28 14:37:19 +01:00
parallel Update copyright years. 2021-01-04 10:26:59 +01:00
precompiled libstdc++: Add support for C++20 barriers 2021-01-07 12:52:37 -08:00
pstl libstdc++: Fix up parallel_backend_serial.h [PR97549] 2021-02-23 09:28:14 +01:00
std libstdc++: Optimize std::visit for the common case [PR 78113] 2021-10-01 20:34:48 +01:00
tr1 libstdc++: Fix even more doxygen markup for group close commands 2021-04-09 13:09:23 +01:00
tr2 libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
Makefile.am libstdc++: Move COW string definitions to separate header 2021-07-27 12:04:18 +01:00
Makefile.in libstdc++: Move COW string definitions to separate header 2021-07-27 12:04:18 +01:00