diff options
author | Hans Goudey <h.goudey@me.com> | 2022-08-28 22:33:03 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-08-28 22:33:03 +0300 |
commit | 67f3259c54657996d47112967c9b982f78ebfe6e (patch) | |
tree | 175eef61ff9e52044c56344e47aa93ac40f4c29c /source/blender/blenkernel | |
parent | 28750bcf7e8b73d9da015898a3c0f21ef5d761f2 (diff) |
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
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/intern/curves_geometry.cc | 6 |
1 files changed, 6 insertions, 0 deletions
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<int8_t> 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(); |