Skip to content

Commit 927f2e1

Browse files
committed
Use likely() in PtrToArg<T *> when checking for null Object *s
1 parent dc91479 commit 927f2e1

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

core/variant/method_ptrcall.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,7 @@ MAKE_PTRARG_BY_REFERENCE(Variant);
159159
template <typename T>
160160
struct PtrToArg<T *> {
161161
_FORCE_INLINE_ static T *convert(const void *p_ptr) {
162-
if (p_ptr == nullptr) {
163-
return nullptr;
164-
}
165-
return const_cast<T *>(*reinterpret_cast<T *const *>(p_ptr));
162+
return likely(p_ptr) ? const_cast<T *>(*reinterpret_cast<T *const *>(p_ptr)) : nullptr;
166163
}
167164
typedef Object *EncodeT;
168165
_FORCE_INLINE_ static void encode(T *p_var, void *p_ptr) {
@@ -173,10 +170,7 @@ struct PtrToArg<T *> {
173170
template <typename T>
174171
struct PtrToArg<const T *> {
175172
_FORCE_INLINE_ static const T *convert(const void *p_ptr) {
176-
if (p_ptr == nullptr) {
177-
return nullptr;
178-
}
179-
return *reinterpret_cast<T *const *>(p_ptr);
173+
return likely(p_ptr) ? *reinterpret_cast<T *const *>(p_ptr) : nullptr;
180174
}
181175
typedef const Object *EncodeT;
182176
_FORCE_INLINE_ static void encode(T *p_var, void *p_ptr) {

0 commit comments

Comments
 (0)