Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2022-07-01 03:29:32 +0300
committerHans Goudey <h.goudey@me.com>2022-07-01 03:29:32 +0300
commit4206b302754797ea07684283fa9b677e4ea531d5 (patch)
treebb0a8a1796779c2daa93e23426c87c15fca3c60c /source/blender/blenkernel/intern/curves_utils.cc
parent32e9c9802eb3fb3f85c3dbf791e49ef74a9e2b0a (diff)
Curves: Adjust "for each curve by type" utility
The first change is reusing the same vector for all types. While we don't generally optimize for the multi-type case, it doesn't hurt here. The second change is avoiding calling the corresponding function if there are no curves of a certain type. This avoids creating attributes for types that aren't used, for example.
Diffstat (limited to 'source/blender/blenkernel/intern/curves_utils.cc')
-rw-r--r--source/blender/blenkernel/intern/curves_utils.cc20
1 files changed, 12 insertions, 8 deletions
diff --git a/source/blender/blenkernel/intern/curves_utils.cc b/source/blender/blenkernel/intern/curves_utils.cc
index 802469399ab..f7db60ee588 100644
--- a/source/blender/blenkernel/intern/curves_utils.cc
+++ b/source/blender/blenkernel/intern/curves_utils.cc
@@ -109,14 +109,18 @@ void foreach_curve_by_type(const VArray<int8_t> &types,
FunctionRef<void(IndexMask)> bezier_fn,
FunctionRef<void(IndexMask)> nurbs_fn)
{
- Vector<int64_t> catmull_rom;
- Vector<int64_t> poly;
- Vector<int64_t> bezier;
- Vector<int64_t> nurbs;
- catmull_rom_fn(indices_for_type(types, counts, CURVE_TYPE_CATMULL_ROM, selection, catmull_rom));
- poly_fn(indices_for_type(types, counts, CURVE_TYPE_POLY, selection, poly));
- bezier_fn(indices_for_type(types, counts, CURVE_TYPE_BEZIER, selection, bezier));
- nurbs_fn(indices_for_type(types, counts, CURVE_TYPE_NURBS, selection, nurbs));
+ Vector<int64_t> indices;
+ auto call_if_not_empty = [&](const CurveType type, FunctionRef<void(IndexMask)> fn) {
+ indices.clear();
+ const IndexMask mask = indices_for_type(types, counts, type, selection, indices);
+ if (!mask.is_empty()) {
+ fn(mask);
+ }
+ };
+ call_if_not_empty(CURVE_TYPE_CATMULL_ROM, catmull_rom_fn);
+ call_if_not_empty(CURVE_TYPE_POLY, poly_fn);
+ call_if_not_empty(CURVE_TYPE_BEZIER, bezier_fn);
+ call_if_not_empty(CURVE_TYPE_NURBS, nurbs_fn);
}
} // namespace blender::bke::curves