[Bf-blender-cvs] [b6cb04cd0f6] temp-cpp-type-cleanup: improve hashing

Jacques Lucke noreply at git.blender.org
Sun Jun 27 17:07:05 CEST 2021


Commit: b6cb04cd0f6ed548169815906f17803ce091965a
Author: Jacques Lucke
Date:   Sun Jun 27 16:49:38 2021 +0200
Branches: temp-cpp-type-cleanup
https://developer.blender.org/rBb6cb04cd0f6ed548169815906f17803ce091965a

improve hashing

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

M	source/blender/functions/FN_cpp_type.hh
M	source/blender/functions/intern/multi_function_builder.cc
M	source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc

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

diff --git a/source/blender/functions/FN_cpp_type.hh b/source/blender/functions/FN_cpp_type.hh
index 0b7e378dcc2..4de0533a46d 100644
--- a/source/blender/functions/FN_cpp_type.hh
+++ b/source/blender/functions/FN_cpp_type.hh
@@ -576,6 +576,14 @@ class CPPType : NonCopyable, NonMovable {
     return m_.hash(value);
   }
 
+  uint64_t hash_or_fallback(const void *value, uint64_t fallback_hash) const
+  {
+    if (this->is_hashable()) {
+      return this->hash(value);
+    }
+    return fallback_hash;
+  }
+
   /**
    * Get a pointer to a constant value of this type. The specific value depends on the type.
    * It is usually a zero-initialized or default constructed value.
diff --git a/source/blender/functions/intern/multi_function_builder.cc b/source/blender/functions/intern/multi_function_builder.cc
index 69b2b6e0b93..c6b3b808130 100644
--- a/source/blender/functions/intern/multi_function_builder.cc
+++ b/source/blender/functions/intern/multi_function_builder.cc
@@ -41,7 +41,7 @@ void CustomMF_GenericConstant::call(IndexMask mask,
 
 uint64_t CustomMF_GenericConstant::hash() const
 {
-  return type_.hash(value_);
+  return type_.hash_or_fallback(value_, (uintptr_t)this);
 }
 
 bool CustomMF_GenericConstant::equals(const MultiFunction &other) const
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc
index eeb77abd624..15d419a003a 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc
@@ -189,6 +189,7 @@ Array<uint32_t> get_geometry_element_ids_as_uints(const GeometryComponent &compo
   if (hash_attribute) {
     BLI_assert(hashes.size() == hash_attribute->size());
     const CPPType &cpp_type = hash_attribute->type();
+    BLI_assert(cpp_type.is_hashable());
     GVArray_GSpan items{*hash_attribute};
     threading::parallel_for(hashes.index_range(), 512, [&](IndexRange range) {
       for (const int i : range) {



More information about the Bf-blender-cvs mailing list