diff --git a/rtc_base/function.h b/rtc_base/function.h index cbc5f7dabd..005c360e9e 100644 --- a/rtc_base/function.h +++ b/rtc_base/function.h @@ -32,24 +32,26 @@ template struct CallHelpers; template struct CallHelpers { + // 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 static RetT CallVoidPtr(VoidUnion* vu, ArgT... args) { return (*static_cast(vu->void_ptr))(std::forward(args)...); } + // Helper for calling the `fun_ptr` case of VoidUnion. static RetT CallFunPtr(VoidUnion* vu, ArgT... args) { return (reinterpret_cast(vu->fun_ptr))( std::forward(args)...); } + // Helper for calling the `inline_storage` case of VoidUnion. template static RetT CallInlineStorage(VoidUnion* vu, ArgT... args) { return (*reinterpret_cast(&vu->inline_storage))( std::forward(args)...); } - static RetT DoCall(FunVoid* f, VoidUnion* vu, ArgT... args) { - return reinterpret_cast(f)( - vu, std::forward(args)...); - } }; } // namespace webrtc_function_impl @@ -188,8 +190,9 @@ class UntypedFunction final { template typename webrtc_function_impl::CallHelpers::return_type Call( ArgT&&... args) { - return webrtc_function_impl::CallHelpers::DoCall( - call_, &f_, std::forward(args)...); + return reinterpret_cast< + typename webrtc_function_impl::CallHelpers::function_type*>( + call_)(&f_, std::forward(args)...); } // Returns true iff we don't need to call a destructor. This is guaranteed