From e12498e44e22b723c8772ef1ff0055a91cce6bef Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Thu, 19 Jan 2023 14:16:31 -0600 Subject: [PATCH] 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. --- source/blender/geometry/intern/resample_curves.cc | 4 +--- source/blender/geometry/intern/trim_curves.cc | 12 +++++++----- 2 files changed, 8 insertions(+), 8 deletions(-) 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 evaluated = evaluated_buffer.as_mutable_span().cast(); 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 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(), 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(evaluated_span.typed(), + evaluated_buffer.reinitialize(sizeof(T) * src_evaluated_points_by_curve.size(curve_i)); + MutableSpan evaluated = evaluated_buffer.as_mutable_span().cast(); + src_curves.interpolate_to_evaluated(curve_i, attribute.src.slice(src_points), evaluated); + sample_interval_linear(evaluated, attribute.dst.span.typed(), src_ranges[curve_i], dst_points_by_curve[curve_i],