gcc/libstdc++-v3/include/std
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
..
algorithm libstdc++: Remove unnecessary uses of <utility> 2021-07-27 12:04:18 +01:00
any libstdc++: Reduce header dependencies on <array> and <utility> 2021-07-27 12:04:18 +01:00
array libstdc++: Add [[nodiscard]] to sequence containers 2021-08-04 12:54:29 +01:00
atomic libstdc++: Implement std::atomic<T*>::compare_exchange_weak 2021-09-02 18:22:33 +01:00
barrier [libstdc++] Remove unused hasher instance. 2021-06-08 15:41:31 -07:00
bit libstdc++: Fix <bit> to work freestanding [PR 100060] 2021-04-13 17:54:03 +01:00
bitset libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
charconv libstdc++: Don't check always-true condition [PR101965] 2021-08-19 14:57:41 +01:00
chrono libstdc++: Improvements to Doxygen markup 2021-07-01 18:45:48 +01:00
codecvt Update copyright years. 2021-01-04 10:26:59 +01:00
complex libstdc++: Simplify n-ary arithmetic promotion traits 2021-08-18 14:26:39 +01:00
concepts libstdc++: Implement LWG 3557 change to convertible_to 2021-06-18 11:51:33 -04:00
condition_variable libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
coroutine libstdc++: Make coroutine_handle<_Promise>::from_address() noexcept [PR 99021] 2021-02-09 12:31:52 +00:00
deque Update copyright years. 2021-01-04 10:26:59 +01:00
execution Update copyright years. 2021-01-04 10:26:59 +01:00
filesystem Update copyright years. 2021-01-04 10:26:59 +01:00
forward_list Update copyright years. 2021-01-04 10:26:59 +01:00
fstream libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
functional libstdc++: Define std::invoke_r for C++23 (P2136R3) 2021-09-02 17:48:45 +01:00
future libstdc++: Reduce headers included by <future> 2021-07-23 13:27:45 +01:00
iomanip Update copyright years. 2021-01-04 10:26:59 +01:00
ios Update copyright years. 2021-01-04 10:26:59 +01:00
iosfwd Update copyright years. 2021-01-04 10:26:59 +01:00
iostream libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
istream libstdc++: Fix constraints for rvalue stream insertion/extraction 2021-05-07 23:45:52 +01:00
iterator Update copyright years. 2021-01-04 10:26:59 +01:00
latch libstdc++: Fix whitespace in license boilerplate 2021-04-21 12:59:58 +01:00
limits libstdc++: Use __extension__ instead of diagnostic pragmas 2021-07-16 15:03:03 +01:00
list Update copyright years. 2021-01-04 10:26:59 +01:00
locale Update copyright years. 2021-01-04 10:26:59 +01:00
map Update copyright years. 2021-01-04 10:26:59 +01:00
memory libstdc++: Remove garbage collection support for C++23 [P2186R2] 2021-06-22 20:58:43 +01:00
memory_resource libstdc++: Specialize allocator_traits<pmr::polymorphic_allocator<T>> 2021-08-03 15:30:36 +01:00
mutex libstdc++: Only use __gthread_yield if gthreads is available 2021-07-09 15:13:38 +01:00
numbers Update copyright years. 2021-01-04 10:26:59 +01:00
numeric libstdc++: Replace incorrect static assertion in std::reduce [PR95833] 2021-06-18 14:46:58 +01:00
optional libstdc++: Add noexcept to std::nullopt_t constructor 2021-09-16 23:06:38 +01:00
ostream libstdc++: Avoid intercepting exception in ostream::write 2021-06-25 18:47:44 +01:00
queue Update copyright years. 2021-01-04 10:26:59 +01:00
random Update copyright years. 2021-01-04 10:26:59 +01:00
ranges libstdc++: Add default template argument to basic_istream_view 2021-08-23 16:17:10 +01:00
ratio libstdc++: Suppress redundant definitions of inline variables 2021-08-03 15:41:11 +01:00
regex libstdc++: Reduce use of debug containers in <regex> 2021-08-09 20:46:56 +01:00
scoped_allocator libstdc++: Improve Doxygen documentation groups [PR 101258] 2021-07-01 00:25:46 +01:00
semaphore libstdc++: Remove #error from <semaphore> implementation [PR 100179] 2021-04-22 13:59:32 +01:00
set Update copyright years. 2021-01-04 10:26:59 +01:00
shared_mutex libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
source_location Update copyright years. 2021-01-04 10:26:59 +01:00
span libstdc++: Add missing constraint to std::span deduction guide [PR102280] 2021-09-16 22:59:47 +01:00
sstream Update copyright years. 2021-01-04 10:26:59 +01:00
stack Update copyright years. 2021-01-04 10:26:59 +01:00
stdexcept libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
stop_token libstdc++: Remove TODO comment 2021-05-10 21:10:34 +01:00
streambuf libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
string Update copyright years. 2021-01-04 10:26:59 +01:00
string_view libstdc++: Add noexcept-specifier to basic_string_view(It, End) 2021-07-14 12:23:33 +01:00
syncstream libstdc++: Remove noexcept from syncbuf::swap (LWG 3498) 2021-06-25 18:41:30 +01:00
system_error libstdc++: Improvements to Doxygen markup 2021-07-01 18:45:48 +01:00
thread libstdc++: Fix std::jthread assertion and re-enable skipped test 2021-05-17 17:56:57 +01:00
tuple libstdc++: Fix last std::tuple constructor missing 'constexpr' [PR102270] 2021-09-17 20:43:34 +01:00
type_traits libstdc++: Add std::is_layout_compatible trait for C++20 2021-08-24 16:12:44 +01:00
typeindex Update copyright years. 2021-01-04 10:26:59 +01:00
unordered_map Update copyright years. 2021-01-04 10:26:59 +01:00
unordered_set Update copyright years. 2021-01-04 10:26:59 +01:00
utility libstdc++: Add conditional noexcept to std::exchange 2021-08-17 14:22:49 +01:00
valarray libstdc++: Fix non-reserved names in <valarray> 2021-08-25 22:29:26 +01:00
variant libstdc++: Optimize std::visit for the common case [PR 78113] 2021-10-01 20:34:48 +01:00
vector Update copyright years. 2021-01-04 10:26:59 +01:00
version libstdc++: Allow visiting inherited variants [PR 90943] 2021-10-01 20:34:48 +01:00