[Bf-blender-cvs] [8fd65a22524] master: Functions: use new is-equal and hash function of CPPType

Jacques Lucke noreply at git.blender.org
Fri Jul 10 12:58:23 CEST 2020


Commit: 8fd65a225240fff200facdb916b0bf2c3026df7d
Author: Jacques Lucke
Date:   Fri Jul 10 12:56:57 2020 +0200
Branches: master
https://developer.blender.org/rB8fd65a225240fff200facdb916b0bf2c3026df7d

Functions: use new is-equal and hash function of CPPType

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

M	source/blender/functions/FN_multi_function_builder.hh
M	source/blender/functions/intern/multi_function_builder.cc

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

diff --git a/source/blender/functions/FN_multi_function_builder.hh b/source/blender/functions/FN_multi_function_builder.hh
index 9be785f5a70..5905d1cc315 100644
--- a/source/blender/functions/FN_multi_function_builder.hh
+++ b/source/blender/functions/FN_multi_function_builder.hh
@@ -202,8 +202,6 @@ template<typename Mut1> class CustomMF_SM : public MultiFunction {
   }
 };
 
-bool generic_values_are_equal(const CPPType &type, const void *a, const void *b);
-
 /**
  * A multi-function that outputs the same value every time. The value is not owned by an instance
  * of this function. The caller is responsible for destructing and freeing the value.
@@ -271,8 +269,9 @@ template<typename T> class CustomMF_Constant : public MultiFunction {
     const CustomMF_GenericConstant *other2 = dynamic_cast<const CustomMF_GenericConstant *>(
         &other);
     if (other2 != nullptr) {
-      if (CPPType::get<T>() == other2->type_) {
-        return generic_values_are_equal(other2->type_, (const void *)&value_, other2->value_);
+      const CPPType &type = CPPType::get<T>();
+      if (type == other2->type_) {
+        return type.is_equal((const void *)&value_, other2->value_);
       }
     }
     return false;
diff --git a/source/blender/functions/intern/multi_function_builder.cc b/source/blender/functions/intern/multi_function_builder.cc
index 0a640b009cd..889a2595aab 100644
--- a/source/blender/functions/intern/multi_function_builder.cc
+++ b/source/blender/functions/intern/multi_function_builder.cc
@@ -14,10 +14,8 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#include "FN_cpp_types.hh"
 #include "FN_multi_function_builder.hh"
 
-#include "BLI_float3.hh"
 #include "BLI_hash.hh"
 
 namespace blender::fn {
@@ -41,31 +39,7 @@ void CustomMF_GenericConstant::call(IndexMask mask,
 
 uint CustomMF_GenericConstant::hash() const
 {
-  if (type_ == CPPType_float3) {
-    return DefaultHash<float3>{}(*(float3 *)value_);
-  }
-  if (type_ == CPPType_int32) {
-    return DefaultHash<int32_t>{}(*(int32_t *)value_);
-  }
-  if (type_ == CPPType_float) {
-    return DefaultHash<float>{}(*(float *)value_);
-  }
-  return MultiFunction::hash();
-}
-
-/* This should be moved into CPPType. */
-bool generic_values_are_equal(const CPPType &type, const void *a, const void *b)
-{
-  if (type == CPPType_float3) {
-    return *(float3 *)a == *(float3 *)b;
-  }
-  if (type == CPPType_int32) {
-    return *(int *)a == *(int *)b;
-  }
-  if (type == CPPType_float) {
-    return *(float *)a == *(float *)b;
-  }
-  return false;
+  return type_.hash(value_);
 }
 
 bool CustomMF_GenericConstant::equals(const MultiFunction &other) const
@@ -77,7 +51,7 @@ bool CustomMF_GenericConstant::equals(const MultiFunction &other) const
   if (type_ != _other->type_) {
     return false;
   }
-  return generic_values_are_equal(type_, value_, _other->value_);
+  return type_.is_equal(value_, _other->value_);
 }
 
 static std::string gspan_to_string(GSpan array)



More information about the Bf-blender-cvs mailing list