From 8d63293c46e9bd68f5fbeddae12a0d433461e2f1 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Thu, 19 Jan 2023 15:22:54 -0600 Subject: [PATCH] Curves: Avoid building evaluated point offsets for poly curves When all the curves are poly curves, skip the work of building a separate array of offsets for the evaluated points (which are the same as the control points). This saves 1-4ms on every reevaluation in test files with many curves. --- source/blender/blenkernel/intern/curves_geometry.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/blender/blenkernel/intern/curves_geometry.cc b/source/blender/blenkernel/intern/curves_geometry.cc index 52da64634b5..26a4f41db48 100644 --- a/source/blender/blenkernel/intern/curves_geometry.cc +++ b/source/blender/blenkernel/intern/curves_geometry.cc @@ -499,6 +499,14 @@ static void calculate_evaluated_offsets(const CurvesGeometry &curves, OffsetIndices CurvesGeometry::evaluated_points_by_curve() const { + if (this->is_single_type(CURVE_TYPE_POLY)) { + /* When all the curves are poly curves, the evaluated offsets are the same as the control + * point offsets, so it's possible to completely avoid building a new offsets array. */ + this->runtime->offsets_cache_mutex.ensure( + [&]() { this->runtime->evaluated_offsets_cache.clear_and_shrink(); }); + return this->points_by_curve(); + } + this->runtime->offsets_cache_mutex.ensure([&]() { this->runtime->evaluated_offsets_cache.resize(this->curves_num() + 1);