AK: Avoid double "is" check in as_if<T> when type must be dynamic_casted
Before this change, the is<T> check simplified down to a dynamic_cast, which meant we did two dynamic_casts in a row for no reason.
This commit is contained in:
parent
95a9ea68a0
commit
b7ba863bf7
1 changed files with 2 additions and 2 deletions
|
|
@ -38,9 +38,9 @@ ALWAYS_INLINE bool is(NonnullRefPtr<InputType> const& input)
|
|||
template<typename OutputType, typename InputType>
|
||||
ALWAYS_INLINE CopyConst<InputType, OutputType>* as_if(InputType& input)
|
||||
{
|
||||
if (!is<OutputType>(input))
|
||||
return nullptr;
|
||||
if constexpr (requires { static_cast<CopyConst<InputType, OutputType>*>(&input); }) {
|
||||
if (!is<OutputType>(input))
|
||||
return nullptr;
|
||||
return static_cast<CopyConst<InputType, OutputType>*>(&input);
|
||||
}
|
||||
return dynamic_cast<CopyConst<InputType, OutputType>*>(&input);
|
||||
|
|
|
|||
Loading…
Reference in a new issue