[Bf-blender-cvs] [e12498e44e2] master: Cleanup: Avoid reallocations when evaluating curve in trim node

Hans Goudey noreply at git.blender.org
Thu Jan 19 22:40:14 CET 2023


Commit: e12498e44e22b723c8772ef1ff0055a91cce6bef
Author: Hans Goudey
Date:   Thu Jan 19 14:16:31 2023 -0600
Branches: master
https://developer.blender.org/rBe12498e44e22b723c8772ef1ff0055a91cce6bef

Cleanup: Avoid reallocations when evaluating curve in trim node

Use the same method as the resample node to use a single vector for
each thread. This avoids an allocation for each attribute of each curve.

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

M	source/blender/geometry/intern/resample_curves.cc
M	source/blender/geometry/intern/trim_curves.cc

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

diff --git a/source/blender/geometry/intern/resample_curves.cc b/source/blender/geometry/intern/resample_curves.cc
index 64827fb6143..eac1d7d8d81 100644
--- a/source/blender/geometry/intern/resample_curves.cc
+++ b/source/blender/geometry/intern/resample_curves.cc
@@ -336,9 +336,7 @@ static CurvesGeometry resample_to_uniform(const CurvesGeometry &src_curves,
                                              dst.slice(dst_points));
           }
           else {
-            const int evaluated_size = evaluated_points_by_curve.size(i_curve);
-            evaluated_buffer.clear();
-            evaluated_buffer.resize(sizeof(T) * evaluated_size);
+            evaluated_buffer.reinitialize(sizeof(T) * evaluated_points_by_curve.size(i_curve));
             MutableSpan<T> evaluated = evaluated_buffer.as_mutable_span().cast<T>();
             src_curves.interpolate_to_evaluated(i_curve, src.slice(src_points), evaluated);
 
diff --git a/source/blender/geometry/intern/trim_curves.cc b/source/blender/geometry/intern/trim_curves.cc
index 0879718a73a..1ab330c3c0a 100644
--- a/source/blender/geometry/intern/trim_curves.cc
+++ b/source/blender/geometry/intern/trim_curves.cc
@@ -787,13 +787,15 @@ static void trim_evaluated_curves(const bke::CurvesGeometry &src_curves,
       using T = decltype(dummy);
 
       threading::parallel_for(selection.index_range(), 512, [&](const IndexRange range) {
+        Vector<std::byte> evaluated_buffer;
         for (const int64_t curve_i : selection.slice(range)) {
+          const IndexRange src_points = src_points_by_curve[curve_i];
+
           /* Interpolate onto the evaluated point domain and sample the evaluated domain. */
-          GArray<> evaluated_data(CPPType::get<T>(), src_evaluated_points_by_curve.size(curve_i));
-          GMutableSpan evaluated_span = evaluated_data.as_mutable_span();
-          src_curves.interpolate_to_evaluated(
-              curve_i, attribute.src.slice(src_points_by_curve[curve_i]), evaluated_span);
-          sample_interval_linear<T>(evaluated_span.typed<T>(),
+          evaluated_buffer.reinitialize(sizeof(T) * src_evaluated_points_by_curve.size(curve_i));
+          MutableSpan<T> evaluated = evaluated_buffer.as_mutable_span().cast<T>();
+          src_curves.interpolate_to_evaluated(curve_i, attribute.src.slice(src_points), evaluated);
+          sample_interval_linear<T>(evaluated,
                                     attribute.dst.span.typed<T>(),
                                     src_ranges[curve_i],
                                     dst_points_by_curve[curve_i],



More information about the Bf-blender-cvs mailing list