[Bf-blender-cvs] [4206b302754] master: Curves: Adjust "for each curve by type" utility

Hans Goudey noreply at git.blender.org
Fri Jul 1 02:40:29 CEST 2022


Commit: 4206b302754797ea07684283fa9b677e4ea531d5
Author: Hans Goudey
Date:   Thu Jun 30 19:29:32 2022 -0500
Branches: master
https://developer.blender.org/rB4206b302754797ea07684283fa9b677e4ea531d5

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.

===================================================================

M	source/blender/blenkernel/intern/curves_utils.cc

===================================================================

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



More information about the Bf-blender-cvs mailing list