[Bf-blender-cvs] [dfd63bf1e47] master: Curves: Avoid reallocations when evaluating NURBS curves

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


Commit: dfd63bf1e47ee4558ac0eb84c2ae3e8a31d8401d
Author: Hans Goudey
Date:   Thu Jan 19 14:29:14 2023 -0600
Branches: master
https://developer.blender.org/rBdfd63bf1e47ee4558ac0eb84c2ae3e8a31d8401d

Curves: Avoid reallocations when evaluating NURBS curves

I didn't detect a noticeable performance difference in a basic test,
but this is better in principle anyway.

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

M	source/blender/blenkernel/intern/curves_geometry.cc

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

diff --git a/source/blender/blenkernel/intern/curves_geometry.cc b/source/blender/blenkernel/intern/curves_geometry.cc
index 5944c557941..52da64634b5 100644
--- a/source/blender/blenkernel/intern/curves_geometry.cc
+++ b/source/blender/blenkernel/intern/curves_geometry.cc
@@ -562,6 +562,7 @@ void CurvesGeometry::ensure_nurbs_basis_cache() const
     const VArray<int8_t> knots_modes = this->nurbs_knots_modes();
 
     threading::parallel_for(nurbs_mask.index_range(), 64, [&](const IndexRange range) {
+      Vector<float, 32> knots;
       for (const int curve_index : nurbs_mask.slice(range)) {
         const IndexRange points = points_by_curve[curve_index];
         const IndexRange evaluated_points = evaluated_points_by_curve[curve_index];
@@ -575,8 +576,7 @@ void CurvesGeometry::ensure_nurbs_basis_cache() const
           continue;
         }
 
-        const int knots_num = curves::nurbs::knots_num(points.size(), order, is_cyclic);
-        Array<float> knots(knots_num);
+        knots.reinitialize(curves::nurbs::knots_num(points.size(), order, is_cyclic));
         curves::nurbs::calculate_knots(points.size(), mode, order, is_cyclic, knots);
         curves::nurbs::calculate_basis_cache(points.size(),
                                              evaluated_points.size(),



More information about the Bf-blender-cvs mailing list