[Bf-blender-cvs] [bd5be7c70ad] functions: Rename TemporaryVector/Array to LargeScopedVector/Array

Jacques Lucke noreply at git.blender.org
Tue Dec 17 13:53:56 CET 2019


Commit: bd5be7c70ad0e4480c2cdf23665cf462c86f8fb0
Author: Jacques Lucke
Date:   Tue Dec 17 11:40:26 2019 +0100
Branches: functions
https://developer.blender.org/rBbd5be7c70ad0e4480c2cdf23665cf462c86f8fb0

Rename TemporaryVector/Array to LargeScopedVector/Array

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

M	source/blender/blenkernel/intern/inlined_node_tree.cc
M	source/blender/blenlib/BLI_array_cxx.h
M	source/blender/blenlib/BLI_temporary_allocator.h
M	source/blender/blenlib/BLI_vector.h
M	source/blender/functions/intern/multi_functions/mixed.cc
M	source/blender/functions/intern/multi_functions/surface_hook.cc
M	source/blender/functions/intern/multi_functions/util.h
M	source/blender/modifiers/intern/MOD_functiondeform_cxx.cc
M	source/blender/simulations/bparticles/action_interface.hpp
M	source/blender/simulations/bparticles/emitters.cpp
M	source/blender/simulations/bparticles/events.cpp
M	source/blender/simulations/bparticles/integrator.cpp
M	source/blender/simulations/bparticles/particle_function.hpp
M	source/blender/simulations/bparticles/simulate.cpp

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

diff --git a/source/blender/blenkernel/intern/inlined_node_tree.cc b/source/blender/blenkernel/intern/inlined_node_tree.cc
index 341e842bc47..62a4eb77147 100644
--- a/source/blender/blenkernel/intern/inlined_node_tree.cc
+++ b/source/blender/blenkernel/intern/inlined_node_tree.cc
@@ -267,7 +267,7 @@ BLI_NOINLINE void InlinedNodeTree::expand_group__relink_outputs(const VirtualNod
 BLI_NOINLINE void InlinedNodeTree::insert_linked_nodes_for_vtree_in_id_order(
     const VirtualNodeTree &vtree, Vector<XNode *> &all_nodes, XParentNode *parent)
 {
-  BLI::TemporaryArray<XSocket *> sockets_map(vtree.socket_count());
+  BLI::LargeScopedArray<XSocket *> sockets_map(vtree.socket_count());
 
   /* Insert nodes of group. */
   for (const VNode *vnode : vtree.nodes()) {
diff --git a/source/blender/blenlib/BLI_array_cxx.h b/source/blender/blenlib/BLI_array_cxx.h
index 7f5f2b2beb9..6cab335ac1d 100644
--- a/source/blender/blenlib/BLI_array_cxx.h
+++ b/source/blender/blenlib/BLI_array_cxx.h
@@ -223,7 +223,14 @@ template<typename T, uint N = 4, typename Allocator = GuardedAllocator> class Ar
   }
 };
 
-template<typename T> using TemporaryArray = Array<T, 4, TemporaryAllocator>;
+/**
+ * Use this when the following assumptions hold:
+ *   - The number of elements in the array is known.
+ *   - The array is usually relatively large (so that it does not fit in inline storage).
+ *   - Is used in the scope of some function. So it will be freed soon.
+ *   - The scope is not in a recursive function.
+ */
+template<typename T> using LargeScopedArray = Array<T, 4, TemporaryAllocator>;
 
 }  // namespace BLI
 
diff --git a/source/blender/blenlib/BLI_temporary_allocator.h b/source/blender/blenlib/BLI_temporary_allocator.h
index 6bb15f9f695..5f0112d5b19 100644
--- a/source/blender/blenlib/BLI_temporary_allocator.h
+++ b/source/blender/blenlib/BLI_temporary_allocator.h
@@ -39,8 +39,8 @@
  * If the requested size is too large, there is a fallback to normal allocation. The allocation
  * overhead is probably very small in these cases anyway.
  *
- * The best way to use this allocator is to use one of the prepared containers like TemporaryVector
- * and TemporaryArray.
+ * The best way to use this allocator is to use one of the prepared containers like
+ * LargeScopedVector and LargeScopedArray.
  */
 
 #ifndef __BLI_TEMPORARY_ALLOCATOR_H__
diff --git a/source/blender/blenlib/BLI_vector.h b/source/blender/blenlib/BLI_vector.h
index 0f011621420..96bb1e1e6bc 100644
--- a/source/blender/blenlib/BLI_vector.h
+++ b/source/blender/blenlib/BLI_vector.h
@@ -644,7 +644,14 @@ template<typename T, uint N = 4, typename Allocator = GuardedAllocator> class Ve
 
 #undef UPDATE_VECTOR_SIZE
 
-template<typename T, uint N = 4> using TemporaryVector = Vector<T, N, TemporaryAllocator>;
+/**
+ * Use this when the following assumptions hold:
+ *   - The number of elements in the vector is not known from the beginning.
+ *   - The vector is usually relatively large (so that it does not fit in inline storage).
+ *   - Is used in the scope of some function. So it will be freed soon.
+ *   - The scope is not in a recursive function.
+ */
+template<typename T, uint N = 4> using LargeScopedVector = Vector<T, N, TemporaryAllocator>;
 
 } /* namespace BLI */
 
diff --git a/source/blender/functions/intern/multi_functions/mixed.cc b/source/blender/functions/intern/multi_functions/mixed.cc
index 472b67da726..27e0aa84ce4 100644
--- a/source/blender/functions/intern/multi_functions/mixed.cc
+++ b/source/blender/functions/intern/multi_functions/mixed.cc
@@ -33,9 +33,9 @@ using BKE::ObjectIDHandle;
 using BLI::float2;
 using BLI::float3;
 using BLI::float4x4;
+using BLI::LargeScopedArray;
 using BLI::rgba_b;
 using BLI::rgba_f;
-using BLI::TemporaryArray;
 
 MF_CombineColor::MF_CombineColor()
 {
@@ -212,7 +212,7 @@ void MF_ObjectVertexPositions::call(MFMask mask, MFParams params, MFContext cont
     float4x4 transform = object->obmat;
 
     Mesh *mesh = (Mesh *)object->data;
-    TemporaryArray<float3> coords(mesh->totvert);
+    LargeScopedArray<float3> coords(mesh->totvert);
     for (uint j = 0; j < mesh->totvert; j++) {
       coords[j] = transform.transform_position(mesh->mvert[j].co);
     }
@@ -586,7 +586,7 @@ static BLI_NOINLINE Vector<int> find_non_close_indices(VirtualListRef<float3> po
 
   BLI_kdtree_3d_balance(kdtree);
 
-  TemporaryArray<bool> keep_index(points.size());
+  LargeScopedArray<bool> keep_index(points.size());
   keep_index.fill(true);
 
   for (uint i : IndexRange(points.size())) {
diff --git a/source/blender/functions/intern/multi_functions/surface_hook.cc b/source/blender/functions/intern/multi_functions/surface_hook.cc
index 210f2d3172a..0e0cc5b171c 100644
--- a/source/blender/functions/intern/multi_functions/surface_hook.cc
+++ b/source/blender/functions/intern/multi_functions/surface_hook.cc
@@ -29,9 +29,9 @@ using BKE::SurfaceHook;
 using BLI::float2;
 using BLI::float3;
 using BLI::float4x4;
+using BLI::LargeScopedArray;
 using BLI::rgba_b;
 using BLI::rgba_f;
-using BLI::TemporaryArray;
 using BLI::VectorAdaptor;
 
 MF_ClosestSurfaceHookOnObject::MF_ClosestSurfaceHookOnObject()
@@ -580,13 +580,13 @@ void MF_SampleObjectSurface::call(MFMask mask, MFParams params, MFContext contex
       continue;
     }
 
-    TemporaryArray<float> triangle_weights(triangles.size());
+    LargeScopedArray<float> triangle_weights(triangles.size());
     compute_triangle_areas(mesh, triangles, triangle_weights);
 
     if (m_use_vertex_weights) {
-      TemporaryArray<float> vertex_weights(mesh->totvert);
+      LargeScopedArray<float> vertex_weights(mesh->totvert);
       if (get_vertex_weights(object, vertex_group_names[i], vertex_weights)) {
-        TemporaryArray<float> vertex_weights_for_triangles(triangles.size());
+        LargeScopedArray<float> vertex_weights_for_triangles(triangles.size());
         vertex_weights_to_triangle_weights(
             mesh, triangles, vertex_weights, vertex_weights_for_triangles);
 
@@ -596,17 +596,17 @@ void MF_SampleObjectSurface::call(MFMask mask, MFParams params, MFContext contex
       }
     }
 
-    TemporaryArray<float> cumulative_weights(triangle_weights.size() + 1);
+    LargeScopedArray<float> cumulative_weights(triangle_weights.size() + 1);
     float total_weight = compute_cumulative_distribution(triangle_weights, cumulative_weights);
     if (total_weight <= 0.0f) {
       continue;
     }
 
     BLI_rng_srandom(rng, seeds[i] + amount * 1000);
-    TemporaryArray<uint> triangle_indices(amount);
+    LargeScopedArray<uint> triangle_indices(amount);
     sample_cumulative_distribution(rng, cumulative_weights, triangle_indices);
 
-    TemporaryArray<float3> bary_coords(amount);
+    LargeScopedArray<float3> bary_coords(amount);
     compute_random_uniform_bary_coords(rng, bary_coords);
 
     MutableArrayRef<SurfaceHook> r_hooks = r_hooks_per_index.allocate_and_default_construct(
diff --git a/source/blender/functions/intern/multi_functions/util.h b/source/blender/functions/intern/multi_functions/util.h
index e1d4788d57e..0c37fdfbc7c 100644
--- a/source/blender/functions/intern/multi_functions/util.h
+++ b/source/blender/functions/intern/multi_functions/util.h
@@ -4,7 +4,7 @@
 
 namespace FN {
 
-using BLI::TemporaryVector;
+using BLI::LargeScopedVector;
 
 template<typename T, typename FuncT, typename EqualFuncT = std::equal_to<T>>
 void group_indices_by_same_value(ArrayRef<uint> indices,
@@ -32,7 +32,7 @@ void group_indices_by_same_value(ArrayRef<uint> indices,
     }
     seen_values.append(value);
 
-    TemporaryVector<uint> indices_with_value;
+    LargeScopedVector<uint> indices_with_value;
     for (uint j : indices.drop_front(i)) {
       if (equal(values[j], value)) {
         indices_with_value.append(j);
diff --git a/source/blender/modifiers/intern/MOD_functiondeform_cxx.cc b/source/blender/modifiers/intern/MOD_functiondeform_cxx.cc
index 77cc00d17af..612b2ea3bd5 100644
--- a/source/blender/modifiers/intern/MOD_functiondeform_cxx.cc
+++ b/source/blender/modifiers/intern/MOD_functiondeform_cxx.cc
@@ -16,7 +16,7 @@ using BKE::VNode;
 using BLI::ArrayRef;
 using BLI::float3;
 using BLI::IndexRange;
-using BLI::TemporaryVector;
+using BLI::LargeScopedVector;
 using BLI::Vector;
 using FN::MFContext;
 using FN::MFContextBuilder;
@@ -55,7 +55,7 @@ void MOD_functiondeform_do(FunctionDeformModifierData *fdmd,
   params_builder.add_readonly_single_input(&fdmd->control1);
   params_builder.add_readonly_single_input(&fdmd->control2);
 
-  TemporaryVector<float3> output_vectors(numVerts);
+  LargeScopedVector<float3> output_vectors(numVerts);
   params_builder.add_single_output<float3>(output_vectors);
 
   float current_time = DEG_get_ctime(ctx->depsgraph);
diff --git a/source/blender/simulations/bparticles/action_interface.hpp b/source/blender/simulations/bparticles/action_interface.hpp
index 2e8981eb880..7fdfc23e916 100644
--- a/source/blender/simulations/bparticles/action_interface.hpp
+++ b/source/blender/simulations/bparticles/action_interface.hpp
@@ -9,7 +9,7 @@
 
 namespace BParticles {
 
-using BLI::TemporaryArray;
+using BLI::LargeScopedArray;
 using FN::AttributesRefGroup;
 
 class ActionContext {
@@ -142,7 +142,7 @@ inline void Action::execute_from_emitter(AttributesRefGroup &new_particles,
     build_context(range, (void *)action_context);
 
     AttributesRef offsets(info, buffers, range_size);
-    TemporaryArray<float> durations(range_size);
+    LargeScopedArray<float> durations(range_size);
     durations.fill(0);
 
     ActionInterface action_interface(emitter_interface.particle_allocator(),
@@ -191,7 +191,7 @@ inline void Action::execute_from_offset_handler(OffsetHandlerInterface &offset_h
   ActionContext &used_action_context = (action_context == nullptr) ? empty_action_context :
                                                                      *action_context;
 
-  TemporaryArray<float> current_times(offset_handler_interface.array_size());
+  LargeScopedArray<float> current_times(offset_handler_interface.array_size());
   for (uint pindex : offset_handler_interface.pindices()) {
     current_times[pindex] = offset_handler_interface.time_span(pindex).start();
   }
@@ -232,7 +232,7 @@ inline void Action::execute_for_new_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list