diff --git a/AK/TypeCasts.h b/AK/TypeCasts.h index c218ba8568..6ab8101f32 100644 --- a/AK/TypeCasts.h +++ b/AK/TypeCasts.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Andreas Kling + * Copyright (c) 2020-2021, Andreas Kling * All rights reserved. * * Redistribution and use in input and binary forms, with or without @@ -26,24 +26,28 @@ #pragma once +#include #include namespace AK { template -inline bool is(InputType& input) +ALWAYS_INLINE bool is(InputType& input) { + if constexpr (requires { input.template fast_is(); }) { + return input.template fast_is(); + } return dynamic_cast*>(&input); } template -inline bool is(InputType* input) +ALWAYS_INLINE bool is(InputType* input) { return input && is(*input); } template -inline CopyConst* downcast(InputType* input) +ALWAYS_INLINE CopyConst* downcast(InputType* input) { static_assert(IsBaseOf::value); ASSERT(!input || is(*input)); @@ -51,7 +55,7 @@ inline CopyConst* downcast(InputType* input) } template -inline CopyConst& downcast(InputType& input) +ALWAYS_INLINE CopyConst& downcast(InputType& input) { static_assert(IsBaseOf::value); ASSERT(is(input));