[Bf-blender-cvs] [6379f1d0353] functions-experimental-refactor: improve performance when iterating over mask indices

Jacques Lucke noreply at git.blender.org
Fri Nov 1 14:38:37 CET 2019


Commit: 6379f1d0353f90711acae5636e6ce1bba8d87791
Author: Jacques Lucke
Date:   Fri Nov 1 14:37:58 2019 +0100
Branches: functions-experimental-refactor
https://developer.blender.org/rB6379f1d0353f90711acae5636e6ce1bba8d87791

improve performance when iterating over mask indices

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

M	source/blender/blenkernel/BKE_multi_function.h
M	source/blender/blenkernel/BKE_multi_functions.h
M	source/blender/modifiers/intern/MOD_functiondeform_cxx.cc

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

diff --git a/source/blender/blenkernel/BKE_multi_function.h b/source/blender/blenkernel/BKE_multi_function.h
index cfe8fe8a9fd..527d9df4790 100644
--- a/source/blender/blenkernel/BKE_multi_function.h
+++ b/source/blender/blenkernel/BKE_multi_function.h
@@ -189,6 +189,11 @@ class MFMask {
  public:
   MFMask(ArrayRef<uint> indices) : m_indices(indices)
   {
+#ifdef DEBUG
+    for (uint i = 1; i < indices.size(); i++) {
+      BLI_assert(indices[i - 1] < indices[i]);
+    }
+#endif
   }
 
   uint indices_amount() const
@@ -205,6 +210,32 @@ class MFMask {
   {
     return m_indices;
   }
+
+  bool is_range() const
+  {
+    return m_indices.size() > 0 && m_indices.last() - m_indices.first() == m_indices.size() - 1;
+  }
+
+  IndexRange as_range() const
+  {
+    BLI_assert(this->is_range());
+    return IndexRange{m_indices.first(), m_indices.size()};
+  }
+
+  template<typename FuncT> void foreach_index(const FuncT &func) const
+  {
+    if (this->is_range()) {
+      IndexRange range = this->as_range();
+      for (uint i : range) {
+        func(i);
+      }
+    }
+    else {
+      for (uint i : m_indices) {
+        func(i);
+      }
+    }
+  }
 };
 
 class MFContext {
diff --git a/source/blender/blenkernel/BKE_multi_functions.h b/source/blender/blenkernel/BKE_multi_functions.h
index 1805535d969..9b5eb639564 100644
--- a/source/blender/blenkernel/BKE_multi_functions.h
+++ b/source/blender/blenkernel/BKE_multi_functions.h
@@ -106,9 +106,9 @@ template<typename T> class MultiFunction_ConstantValue : public MultiFunction {
   {
     MutableArrayRef<T> output = params.single_output<T>(0, "Output");
 
-    for (uint i : mask.indices()) {
+    mask.foreach_index([&](uint i) {
       new (output.begin() + i) T(m_value);
-    }
+    });
   }
 };
 
diff --git a/source/blender/modifiers/intern/MOD_functiondeform_cxx.cc b/source/blender/modifiers/intern/MOD_functiondeform_cxx.cc
index 1c970cdc807..3d406be86dd 100644
--- a/source/blender/modifiers/intern/MOD_functiondeform_cxx.cc
+++ b/source/blender/modifiers/intern/MOD_functiondeform_cxx.cc
@@ -9,6 +9,7 @@
 #include "BLI_string_map.h"
 #include "BLI_owned_resources.h"
 #include "BLI_stack_cxx.h"
+#include "BLI_timeit.h"
 
 #include "DEG_depsgraph_query.h"



More information about the Bf-blender-cvs mailing list