commit df6809ea3938e70cfea8ebf1485f46145d509a39
parent c693ad2d52236942db018a73632a4b910f54b488
Author: serge-sans-paille <sguelton@mozilla.com>
Date: Mon, 6 Oct 2025 12:30:20 +0000
Bug 1992681 - Cleanup mfbt/FunctionTypeTraits.h r=emilio
- Remove unused headers
- Remove redundant visibility specification
- Simplify SafeTupleElement implementation and remove std::tuple
dependency in the process. I kept the naive recursive version, which
is still faster than the std::tuple_element one, see:
https://ldionne.com/2015/11/29/efficient-parameter-pack-indexing/
Differential Revision: https://phabricator.services.mozilla.com/D267579
Diffstat:
2 files changed, 30 insertions(+), 34 deletions(-)
diff --git a/dom/canvas/WebGLCommandQueue.h b/dom/canvas/WebGLCommandQueue.h
@@ -10,7 +10,6 @@
#include "QueueParamTraits.h"
#include "WebGLTypes.h"
-#include "mozilla/FunctionTypeTraits.h"
#include "mozilla/gfx/Logging.h"
#include "mozilla/ipc/IPDLParamTraits.h"
diff --git a/mfbt/FunctionTypeTraits.h b/mfbt/FunctionTypeTraits.h
@@ -8,7 +8,6 @@
#define mozilla_FunctionTypeTraits_h
#include <cstddef> /* for size_t */
-#include <tuple>
namespace mozilla {
@@ -40,73 +39,71 @@ struct FunctionTypeTraits;
// Remove reference and pointer wrappers, if any.
template <typename T>
-struct FunctionTypeTraits<T&> : public FunctionTypeTraits<T> {};
+struct FunctionTypeTraits<T&> : FunctionTypeTraits<T> {};
template <typename T>
-struct FunctionTypeTraits<T&&> : public FunctionTypeTraits<T> {};
+struct FunctionTypeTraits<T&&> : FunctionTypeTraits<T> {};
template <typename T>
-struct FunctionTypeTraits<T*> : public FunctionTypeTraits<T> {};
+struct FunctionTypeTraits<T*> : FunctionTypeTraits<T> {};
// Extract `operator()` function from callables (e.g. lambdas, std::function).
template <typename T>
-struct FunctionTypeTraits
- : public FunctionTypeTraits<decltype(&T::operator())> {};
+struct FunctionTypeTraits : FunctionTypeTraits<decltype(&T::operator())> {};
namespace detail {
-
-// If `safe`, retrieve the `N`th type from `As`, otherwise `void`.
-// See top description for reason.
-template <bool safe, size_t N, typename... As>
-struct TupleElementSafe;
-template <size_t N, typename... As>
-struct TupleElementSafe<true, N, As...> {
- using Type = typename std::tuple_element<N, std::tuple<As...>>::type;
-};
template <size_t N, typename... As>
-struct TupleElementSafe<false, N, As...> {
- using Type = void;
+struct SafePackElement;
+
+template <size_t N>
+struct SafePackElement<N> {
+ using type = void;
};
-template <typename R, typename... As>
-struct FunctionTypeTraitsHelper {
- using ReturnType = R;
- static constexpr size_t arity = sizeof...(As);
- template <size_t N>
- using ParameterType =
- typename TupleElementSafe<(N < sizeof...(As)), N, As...>::Type;
+template <typename A, typename... As>
+struct SafePackElement<0, A, As...> {
+ using type = A;
};
+template <size_t N, typename A, typename... As>
+struct SafePackElement<N, A, As...> : SafePackElement<N - 1, As...> {};
+
+template <size_t N, typename... As>
+using SafePackElementType = typename SafePackElement<N, As...>::type;
+
} // namespace detail
// Specialization for free functions.
template <typename R, typename... As>
-struct FunctionTypeTraits<R(As...)>
- : detail::FunctionTypeTraitsHelper<R, As...> {};
+struct FunctionTypeTraits<R(As...)> {
+ using ReturnType = R;
+ static constexpr size_t arity = sizeof...(As);
+ template <size_t N>
+ using ParameterType = detail::SafePackElementType<N, As...>;
+};
// Specialization for non-const member functions.
template <typename C, typename R, typename... As>
-struct FunctionTypeTraits<R (C::*)(As...)>
- : detail::FunctionTypeTraitsHelper<R, As...> {};
+struct FunctionTypeTraits<R (C::*)(As...)> : FunctionTypeTraits<R(As...)> {};
// Specialization for const member functions.
template <typename C, typename R, typename... As>
struct FunctionTypeTraits<R (C::*)(As...) const>
- : detail::FunctionTypeTraitsHelper<R, As...> {};
+ : FunctionTypeTraits<R(As...)> {};
#ifdef NS_HAVE_STDCALL
// Specialization for __stdcall free functions.
template <typename R, typename... As>
-struct FunctionTypeTraits<R NS_STDCALL(As...)>
- : detail::FunctionTypeTraitsHelper<R, As...> {};
+struct FunctionTypeTraits<R NS_STDCALL(As...)> : FunctionTypeTraits<R(As...)> {
+};
// Specialization for __stdcall non-const member functions.
template <typename C, typename R, typename... As>
struct FunctionTypeTraits<R (NS_STDCALL C::*)(As...)>
- : detail::FunctionTypeTraitsHelper<R, As...> {};
+ : FunctionTypeTraits<R(As...)> {};
// Specialization for __stdcall const member functions.
template <typename C, typename R, typename... As>
struct FunctionTypeTraits<R (NS_STDCALL C::*)(As...) const>
- : detail::FunctionTypeTraitsHelper<R, As...> {};
+ : FunctionTypeTraitsHelper<R(As...)> {};
#endif // NS_HAVE_STDCALL
} // namespace mozilla