[Bf-blender-cvs] [0ebb98ab3da] functions: cleanup

Jacques Lucke noreply at git.blender.org
Thu Jan 2 16:38:25 CET 2020


Commit: 0ebb98ab3daed6b1dae16255e1f8312cd67a270e
Author: Jacques Lucke
Date:   Thu Jan 2 15:49:41 2020 +0100
Branches: functions
https://developer.blender.org/rB0ebb98ab3daed6b1dae16255e1f8312cd67a270e

cleanup

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

M	source/blender/blenlib/BLI_parallel.h
M	source/blender/simulations/bparticles/simulate.cpp

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

diff --git a/source/blender/blenlib/BLI_parallel.h b/source/blender/blenlib/BLI_parallel.h
index 490af51b00b..5df7104767f 100644
--- a/source/blender/blenlib/BLI_parallel.h
+++ b/source/blender/blenlib/BLI_parallel.h
@@ -8,6 +8,7 @@
 #endif
 
 #include "BLI_index_range.h"
+#include "BLI_multi_map.h"
 
 namespace BLI {
 
@@ -73,6 +74,25 @@ void parallel_invoke(const FuncT1 &func1, const FuncT2 &func2, const FuncT3 &fun
 #endif
 }
 
+template<typename KeyT, typename ValueT, uint N, typename FuncT>
+void parallel_multi_map_items(const MultiMap<KeyT, ValueT, N> &multi_map, const FuncT &func)
+{
+  ScopedVector<const KeyT *> key_vector;
+  ScopedVector<ArrayRef<ValueT>> values_vector;
+
+  multi_map.foreach_item([&](const KeyT &key, ArrayRef<ValueT> values) {
+    key_vector.append(&key);
+    values_vector.append(values);
+  });
+
+  parallel_for(key_vector.index_range(), [&](uint index) {
+    const KeyT &key = *key_vector[index];
+    ArrayRef<ValueT> values = values_vector[index];
+
+    func(key, values);
+  });
+}
+
 }  // namespace BLI
 
 #endif /* __BLI_PARALLEL_H__ */
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index 2df31c3bb9e..2872031ec26 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -475,26 +475,17 @@ void simulate_particles(SimulationState &simulation_state,
     all_newly_created_particles.add_multiple(newly_created_particles);
   }
 
-  Vector<ParticleSet *> main_sets;
-  Vector<ArrayRef<ParticleSet *>> particle_sets_vector;
+  BLI::parallel_multi_map_items(all_newly_created_particles,
+                                [&](StringRef name, ArrayRef<ParticleSet *> new_particle_sets) {
+                                  ParticleSet &main_set = particles_state.particle_container(name);
 
-  all_newly_created_particles.foreach_item(
-      [&](StringRef name, ArrayRef<ParticleSet *> new_particle_sets) {
-        main_sets.append(&particles_state.particle_container(name));
-        particle_sets_vector.append(new_particle_sets);
-      });
-
-  BLI::parallel_for(main_sets.index_range(), [&](uint index) {
-    ParticleSet &main_set = *main_sets[index];
-    ArrayRef<ParticleSet *> particle_sets = particle_sets_vector[index];
+                                  for (ParticleSet *set : new_particle_sets) {
+                                    main_set.add_particles(*set);
+                                    delete set;
+                                  }
 
-    for (ParticleSet *set : particle_sets) {
-      main_set.add_particles(*set);
-      delete set;
-    }
-
-    delete_tagged_particles_and_reorder(main_set);
-  });
+                                  delete_tagged_particles_and_reorder(main_set);
+                                });
 }
 
 }  // namespace BParticles



More information about the Bf-blender-cvs mailing list