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.
This commit is contained in:
Hans Goudey 2023-01-19 14:16:31 -06:00
parent 4cfa4f7551
commit e12498e44e
2 changed files with 8 additions and 8 deletions

View File

@ -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);

View File

@ -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],