[libcxx-commits] [libcxx] Speed up compilation of common uses of std::visit() by ~8x (PR #164196)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Nov 28 01:26:10 PST 2025
================
@@ -1578,11 +1582,42 @@ _LIBCPP_HIDE_FROM_ABI constexpr void __throw_if_valueless(_Vs&&... __vs) {
}
}
-template < class _Visitor, class... _Vs, typename>
+template <class _Visitor, class... _Vs, typename>
_LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) visit(_Visitor&& __visitor, _Vs&&... __vs) {
- using __variant_detail::__visitation::__variant;
- std::__throw_if_valueless(std::forward<_Vs>(__vs)...);
- return __variant::__visit_value(std::forward<_Visitor>(__visitor), std::forward<_Vs>(__vs)...);
+# define _XDispatchIndex(_I) \
+ case _I: \
+ if constexpr (__variant_size::value > _I) { \
+ return std::forward<_Visitor>(__visitor)(__variant::__get_alt<_I>(std::forward<_Vs>(__vs)...).__value); \
+ } \
+ [[__fallthrough__]]
+# define _XDispatchCount 8 // Speed up compilation for the common cases
----------------
philnik777 wrote:
FWIW I'm not a huge fan of the naming here. More conventional would be something like `_LIBCPP_DISPATCH_COUNT`.
https://github.com/llvm/llvm-project/pull/164196
More information about the libcxx-commits
mailing list