UntypedFunction: Eliminate an unnecessary indirection in the implementation
Bug: webrtc:11943 Change-Id: Ib57b13977910ede430e4228a9d382fb765bf1d84 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/184261 Commit-Queue: Karl Wiberg <kwiberg@webrtc.org> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/master@{#32120}
This commit is contained in:
@ -32,24 +32,26 @@ template <typename T>
|
||||
struct CallHelpers;
|
||||
template <typename RetT, typename... ArgT>
|
||||
struct CallHelpers<RetT(ArgT...)> {
|
||||
// Return type of the three helpers below.
|
||||
using return_type = RetT;
|
||||
// Complete function type of the three helpers below.
|
||||
using function_type = RetT(VoidUnion*, ArgT...);
|
||||
// Helper for calling the `void_ptr` case of VoidUnion.
|
||||
template <typename F>
|
||||
static RetT CallVoidPtr(VoidUnion* vu, ArgT... args) {
|
||||
return (*static_cast<F*>(vu->void_ptr))(std::forward<ArgT>(args)...);
|
||||
}
|
||||
// Helper for calling the `fun_ptr` case of VoidUnion.
|
||||
static RetT CallFunPtr(VoidUnion* vu, ArgT... args) {
|
||||
return (reinterpret_cast<RetT (*)(ArgT...)>(vu->fun_ptr))(
|
||||
std::forward<ArgT>(args)...);
|
||||
}
|
||||
// Helper for calling the `inline_storage` case of VoidUnion.
|
||||
template <typename F>
|
||||
static RetT CallInlineStorage(VoidUnion* vu, ArgT... args) {
|
||||
return (*reinterpret_cast<F*>(&vu->inline_storage))(
|
||||
std::forward<ArgT>(args)...);
|
||||
}
|
||||
static RetT DoCall(FunVoid* f, VoidUnion* vu, ArgT... args) {
|
||||
return reinterpret_cast<RetT (*)(VoidUnion*, ArgT...)>(f)(
|
||||
vu, std::forward<ArgT>(args)...);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace webrtc_function_impl
|
||||
@ -188,8 +190,9 @@ class UntypedFunction final {
|
||||
template <typename Signature, typename... ArgT>
|
||||
typename webrtc_function_impl::CallHelpers<Signature>::return_type Call(
|
||||
ArgT&&... args) {
|
||||
return webrtc_function_impl::CallHelpers<Signature>::DoCall(
|
||||
call_, &f_, std::forward<ArgT>(args)...);
|
||||
return reinterpret_cast<
|
||||
typename webrtc_function_impl::CallHelpers<Signature>::function_type*>(
|
||||
call_)(&f_, std::forward<ArgT>(args)...);
|
||||
}
|
||||
|
||||
// Returns true iff we don't need to call a destructor. This is guaranteed
|
||||
|
Reference in New Issue
Block a user