From 927f2e1e538518b8b1bb8f046bf4c756e3297d03 Mon Sep 17 00:00:00 2001 From: David Snopek Date: Mon, 8 Apr 2024 11:06:56 -0500 Subject: [PATCH] Use `likely()` in `PtrToArg` when checking for null `Object *`s --- core/variant/method_ptrcall.h | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/core/variant/method_ptrcall.h b/core/variant/method_ptrcall.h index 123f2067e24..c8d1241d3d1 100644 --- a/core/variant/method_ptrcall.h +++ b/core/variant/method_ptrcall.h @@ -159,10 +159,7 @@ MAKE_PTRARG_BY_REFERENCE(Variant); template struct PtrToArg { _FORCE_INLINE_ static T *convert(const void *p_ptr) { - if (p_ptr == nullptr) { - return nullptr; - } - return const_cast(*reinterpret_cast(p_ptr)); + return likely(p_ptr) ? const_cast(*reinterpret_cast(p_ptr)) : nullptr; } typedef Object *EncodeT; _FORCE_INLINE_ static void encode(T *p_var, void *p_ptr) { @@ -173,10 +170,7 @@ struct PtrToArg { template struct PtrToArg { _FORCE_INLINE_ static const T *convert(const void *p_ptr) { - if (p_ptr == nullptr) { - return nullptr; - } - return *reinterpret_cast(p_ptr); + return likely(p_ptr) ? *reinterpret_cast(p_ptr) : nullptr; } typedef const Object *EncodeT; _FORCE_INLINE_ static void encode(T *p_var, void *p_ptr) {