[Bf-blender-cvs] [f7e9bc65abf] master: Cleanup: simplify getting value of generic ValueOrField

Jacques Lucke noreply at git.blender.org
Fri Jan 6 22:30:27 CET 2023


Commit: f7e9bc65abf66f80a0efaef1d98ad58c2c278123
Author: Jacques Lucke
Date:   Fri Jan 6 22:30:02 2023 +0100
Branches: master
https://developer.blender.org/rBf7e9bc65abf66f80a0efaef1d98ad58c2c278123

Cleanup: simplify getting value of generic ValueOrField

===================================================================

M	source/blender/functions/FN_field_cpp_type.hh
M	source/blender/functions/FN_field_cpp_type_make.hh

===================================================================

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<int>, 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<void *>(get_value_ptr_(value_or_field));
+    static_assert(offsetof(ValueOrField<int>, 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<ValueType> /*value_type*
   construct_from_field_ = [](void *dst, GField field) {
     new (dst) ValueOrField<T>(Field<T>(std::move(field)));
   };
-  get_value_ptr_ = [](const void *value_or_field) {
-    return (const void *)&((ValueOrField<T> *)value_or_field)->value;
-  };
   get_field_ptr_ = [](const void *value_or_field) -> const GField * {
     return &((ValueOrField<T> *)value_or_field)->field;
   };



More information about the Bf-blender-cvs mailing list