diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-04-30 17:03:16 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-04-30 17:03:16 +0200 |
commit | ef481148b2f3e406521080ce85ea4b401f5cac23 (patch) | |
tree | 006d9151c765006148a91844a886729e2dfcf586 | |
parent | ca3821260441c35a934689b912baa28acd076bdc (diff) | |
parent | 927f2e1e538518b8b1bb8f046bf4c756e3297d03 (diff) | |
download | redot-engine-ef481148b2f3e406521080ce85ea4b401f5cac23.tar.gz |
Merge pull request #90394 from dsnopek/object-ptrcall-null-unlikely
Use `likely()` in `PtrToArg<T *>` when checking for null `Object *`s
-rw-r--r-- | core/variant/method_ptrcall.h | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/core/variant/method_ptrcall.h b/core/variant/method_ptrcall.h index 123f2067e2..c8d1241d3d 100644 --- a/core/variant/method_ptrcall.h +++ b/core/variant/method_ptrcall.h @@ -159,10 +159,7 @@ MAKE_PTRARG_BY_REFERENCE(Variant); template <typename T> struct PtrToArg<T *> { _FORCE_INLINE_ static T *convert(const void *p_ptr) { - if (p_ptr == nullptr) { - return nullptr; - } - return const_cast<T *>(*reinterpret_cast<T *const *>(p_ptr)); + return likely(p_ptr) ? const_cast<T *>(*reinterpret_cast<T *const *>(p_ptr)) : nullptr; } typedef Object *EncodeT; _FORCE_INLINE_ static void encode(T *p_var, void *p_ptr) { @@ -173,10 +170,7 @@ struct PtrToArg<T *> { template <typename T> struct PtrToArg<const T *> { _FORCE_INLINE_ static const T *convert(const void *p_ptr) { - if (p_ptr == nullptr) { - return nullptr; - } - return *reinterpret_cast<T *const *>(p_ptr); + return likely(p_ptr) ? *reinterpret_cast<T *const *>(p_ptr) : nullptr; } typedef const Object *EncodeT; _FORCE_INLINE_ static void encode(T *p_var, void *p_ptr) { |