From 67f3259c54657996d47112967c9b982f78ebfe6e Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Sun, 28 Aug 2022 14:33:03 -0500 Subject: Curves: Avoid creating types array when unnecessary When the curve type attribute doesn't exist, there is no reason to create an array for it only to fill the default value, which will add overhead to subsequent "add" operations. I added a "get_if_single" method to virtual array to simplify this check. Also use the existing functions for filling curve types. Differential Revision: https://developer.blender.org/D15560 --- source/blender/blenkernel/intern/curves_geometry.cc | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source/blender/blenkernel/intern/curves_geometry.cc') diff --git a/source/blender/blenkernel/intern/curves_geometry.cc b/source/blender/blenkernel/intern/curves_geometry.cc index e60523c23da..fe9f6775995 100644 --- a/source/blender/blenkernel/intern/curves_geometry.cc +++ b/source/blender/blenkernel/intern/curves_geometry.cc @@ -255,6 +255,12 @@ void CurvesGeometry::fill_curve_types(const IndexMask selection, const CurveType this->fill_curve_types(type); return; } + if (std::optional single_type = this->curve_types().get_if_single()) { + if (single_type == type) { + /* No need for an array if the types are already a single with the correct type. */ + return; + } + } /* A potential performance optimization is only counting the changed indices. */ this->curve_types_for_write().fill_indices(selection, type); this->update_curve_types(); -- cgit v1.2.3