From dfd63bf1e47ee4558ac0eb84c2ae3e8a31d8401d Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Thu, 19 Jan 2023 14:29:14 -0600 Subject: [PATCH] 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. --- source/blender/blenkernel/intern/curves_geometry.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 knots_modes = this->nurbs_knots_modes(); threading::parallel_for(nurbs_mask.index_range(), 64, [&](const IndexRange range) { + Vector 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 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(),