Variant: Merge get() and validated_get()

Since they do pretty much the same thing. The validated_get() was
renamed to get() since that is more performant.
This commit is contained in:
George Marques 2020-11-20 17:26:19 -03:00
parent 8a9e3524a9
commit c8e3fb8b05
No known key found for this signature in database
GPG Key ID: 046BD46A3201E43D

View File

@ -41,9 +41,6 @@
#define SETGET_STRUCT(m_base_type, m_member_type, m_member) \
struct VariantSetGet_##m_base_type##_##m_member { \
static void get(const Variant *base, Variant *member) { \
*member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member; \
} \
static void validated_get(const Variant *base, Variant *member) { \
VariantTypeAdjust<m_member_type>::adjust(member); \
*VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member; \
} \
@ -72,9 +69,6 @@
#define SETGET_NUMBER_STRUCT(m_base_type, m_member_type, m_member) \
struct VariantSetGet_##m_base_type##_##m_member { \
static void get(const Variant *base, Variant *member) { \
*member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member; \
} \
static void validated_get(const Variant *base, Variant *member) { \
VariantTypeAdjust<m_member_type>::adjust(member); \
*VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member; \
} \
@ -106,9 +100,6 @@
#define SETGET_STRUCT_CUSTOM(m_base_type, m_member_type, m_member, m_custom) \
struct VariantSetGet_##m_base_type##_##m_member { \
static void get(const Variant *base, Variant *member) { \
*member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom; \
} \
static void validated_get(const Variant *base, Variant *member) { \
VariantTypeAdjust<m_member_type>::adjust(member); \
*VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom; \
} \
@ -137,9 +128,6 @@
#define SETGET_NUMBER_STRUCT_CUSTOM(m_base_type, m_member_type, m_member, m_custom) \
struct VariantSetGet_##m_base_type##_##m_member { \
static void get(const Variant *base, Variant *member) { \
*member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom; \
} \
static void validated_get(const Variant *base, Variant *member) { \
VariantTypeAdjust<m_member_type>::adjust(member); \
*VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom; \
} \
@ -171,9 +159,6 @@
#define SETGET_STRUCT_FUNC(m_base_type, m_member_type, m_member, m_setter, m_getter) \
struct VariantSetGet_##m_base_type##_##m_member { \
static void get(const Variant *base, Variant *member) { \
*member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(); \
} \
static void validated_get(const Variant *base, Variant *member) { \
VariantTypeAdjust<m_member_type>::adjust(member); \
*VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(); \
} \
@ -202,9 +187,6 @@
#define SETGET_NUMBER_STRUCT_FUNC(m_base_type, m_member_type, m_member, m_setter, m_getter) \
struct VariantSetGet_##m_base_type##_##m_member { \
static void get(const Variant *base, Variant *member) { \
*member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(); \
} \
static void validated_get(const Variant *base, Variant *member) { \
VariantTypeAdjust<m_member_type>::adjust(member); \
*VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(); \
} \
@ -236,9 +218,6 @@
#define SETGET_STRUCT_FUNC_INDEX(m_base_type, m_member_type, m_member, m_setter, m_getter, m_index) \
struct VariantSetGet_##m_base_type##_##m_member { \
static void get(const Variant *base, Variant *member) { \
*member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(m_index); \
} \
static void validated_get(const Variant *base, Variant *member) { \
VariantTypeAdjust<m_member_type>::adjust(member); \
*VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(m_index); \
} \
@ -347,7 +326,7 @@ static void register_member(Variant::Type p_type, const StringName &p_member) {
sgi.ptr_setter = T::ptr_set;
sgi.getter = T::get;
sgi.validated_getter = T::validated_get;
sgi.validated_getter = T::get;
sgi.ptr_getter = T::ptr_get;
sgi.member_type = T::get_type();
@ -604,18 +583,6 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
#define INDEXED_SETGET_STRUCT_TYPED(m_base_type, m_elem_type) \
struct VariantIndexedSetGet_##m_base_type { \
static void get(const Variant *base, int64_t index, Variant *value, bool &oob) { \
int64_t size = VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); \
if (index < 0) { \
index += size; \
} \
if (index < 0 || index >= size) { \
oob = true; \
return; \
} \
*value = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \
oob = false; \
} \
static void validated_get(const Variant *base, int64_t index, Variant *value, bool &oob) { \
int64_t size = VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); \
if (index < 0) { \
index += size; \
@ -682,18 +649,6 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
#define INDEXED_SETGET_STRUCT_TYPED_NUMERIC(m_base_type, m_elem_type, m_assign_type) \
struct VariantIndexedSetGet_##m_base_type { \
static void get(const Variant *base, int64_t index, Variant *value, bool &oob) { \
int64_t size = VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); \
if (index < 0) { \
index += size; \
} \
if (index < 0 || index >= size) { \
oob = true; \
return; \
} \
*value = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \
oob = false; \
} \
static void validated_get(const Variant *base, int64_t index, Variant *value, bool &oob) { \
int64_t size = VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); \
if (index < 0) { \
index += size; \
@ -765,14 +720,6 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
#define INDEXED_SETGET_STRUCT_BULTIN_NUMERIC(m_base_type, m_elem_type, m_assign_type, m_max) \
struct VariantIndexedSetGet_##m_base_type { \
static void get(const Variant *base, int64_t index, Variant *value, bool &oob) { \
if (index < 0 || index >= m_max) { \
oob = true; \
return; \
} \
*value = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \
oob = false; \
} \
static void validated_get(const Variant *base, int64_t index, Variant *value, bool &oob) { \
if (index < 0 || index >= m_max) { \
oob = true; \
return; \
@ -828,14 +775,6 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
#define INDEXED_SETGET_STRUCT_BULTIN_ACCESSOR(m_base_type, m_elem_type, m_accessor, m_max) \
struct VariantIndexedSetGet_##m_base_type { \
static void get(const Variant *base, int64_t index, Variant *value, bool &oob) { \
if (index < 0 || index >= m_max) { \
oob = true; \
return; \
} \
*value = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))m_accessor[index]; \
oob = false; \
} \
static void validated_get(const Variant *base, int64_t index, Variant *value, bool &oob) { \
if (index < 0 || index >= m_max) { \
oob = true; \
return; \
@ -885,14 +824,6 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
#define INDEXED_SETGET_STRUCT_BULTIN_FUNC(m_base_type, m_elem_type, m_set, m_get, m_max) \
struct VariantIndexedSetGet_##m_base_type { \
static void get(const Variant *base, int64_t index, Variant *value, bool &oob) { \
if (index < 0 || index >= m_max) { \
oob = true; \
return; \
} \
*value = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_get(index); \
oob = false; \
} \
static void validated_get(const Variant *base, int64_t index, Variant *value, bool &oob) { \
if (index < 0 || index >= m_max) { \
oob = true; \
return; \
@ -953,18 +884,6 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
*value = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \
oob = false; \
} \
static void validated_get(const Variant *base, int64_t index, Variant *value, bool &oob) { \
int64_t size = VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); \
if (index < 0) { \
index += size; \
} \
if (index < 0 || index >= size) { \
oob = true; \
return; \
} \
*value = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \
oob = false; \
} \
static void ptr_get(const void *base, int64_t index, void *member) { \
/* avoid ptrconvert for performance*/ \
const m_base_type &v = *reinterpret_cast<const m_base_type *>(base); \
@ -1022,15 +941,6 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
*value = *ptr; \
oob = false; \
} \
static void validated_get(const Variant *base, int64_t index, Variant *value, bool &oob) { \
const Variant *ptr = VariantGetInternalPtr<m_base_type>::get_ptr(base)->getptr(index); \
if (!ptr) { \
oob = true; \
return; \
} \
*value = *ptr; \
oob = false; \
} \
static void ptr_get(const void *base, int64_t index, void *member) { \
/* avoid ptrconvert for performance*/ \
const m_base_type &v = *reinterpret_cast<const m_base_type *>(base); \
@ -1106,7 +1016,7 @@ static void register_indexed_member(Variant::Type p_type) {
sgi.ptr_setter = T::ptr_set;
sgi.getter = T::get;
sgi.validated_getter = T::validated_get;
sgi.validated_getter = T::get;
sgi.ptr_getter = T::ptr_get;
sgi.index_type = T::get_index_type();