From f7e9bc65abf66f80a0efaef1d98ad58c2c278123 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Fri, 6 Jan 2023 22:30:02 +0100 Subject: [PATCH] Cleanup: simplify getting value of generic ValueOrField --- source/blender/functions/FN_field_cpp_type.hh | 8 ++++---- source/blender/functions/FN_field_cpp_type_make.hh | 3 --- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/source/blender/functions/FN_field_cpp_type.hh b/source/blender/functions/FN_field_cpp_type.hh index cbb2a576272..dcb9efcd4f0 100644 --- a/source/blender/functions/FN_field_cpp_type.hh +++ b/source/blender/functions/FN_field_cpp_type.hh @@ -17,7 +17,6 @@ class ValueOrFieldCPPType { private: void (*construct_from_value_)(void *dst, const void *value); void (*construct_from_field_)(void *dst, GField field); - const void *(*get_value_ptr_)(const void *value_or_field); const GField *(*get_field_ptr_)(const void *value_or_field); bool (*is_field_)(const void *value_or_field); GField (*as_field_)(const void *value_or_field); @@ -42,13 +41,14 @@ class ValueOrFieldCPPType { const void *get_value_ptr(const void *value_or_field) const { - return get_value_ptr_(value_or_field); + static_assert(offsetof(ValueOrField, value) == 0); + return value_or_field; } void *get_value_ptr(void *value_or_field) const { - /* Use `const_cast` to avoid duplicating the callback for the non-const case. */ - return const_cast(get_value_ptr_(value_or_field)); + static_assert(offsetof(ValueOrField, value) == 0); + return value_or_field; } const GField *get_field_ptr(const void *value_or_field) const diff --git a/source/blender/functions/FN_field_cpp_type_make.hh b/source/blender/functions/FN_field_cpp_type_make.hh index 7a4112b432b..1ab0f591019 100644 --- a/source/blender/functions/FN_field_cpp_type_make.hh +++ b/source/blender/functions/FN_field_cpp_type_make.hh @@ -17,9 +17,6 @@ inline ValueOrFieldCPPType::ValueOrFieldCPPType(TypeTag /*value_type* construct_from_field_ = [](void *dst, GField field) { new (dst) ValueOrField(Field(std::move(field))); }; - get_value_ptr_ = [](const void *value_or_field) { - return (const void *)&((ValueOrField *)value_or_field)->value; - }; get_field_ptr_ = [](const void *value_or_field) -> const GField * { return &((ValueOrField *)value_or_field)->field; };