Curves: Avoid initializing offsets when first allocated

The offsets array that encodes the sizes of each curve must be filled
anyway, or the curves will be in an invalid state. Calloc is unnecessary
here. To make that situation clearer, fill the offsets with -1 in debug
builds. Always set the first offset to zero though, since that can save
some boilerplate in other areas.
This commit is contained in:
Hans Goudey 2022-06-30 21:42:09 -05:00
parent 7e55ff15b0
commit 276e419671
1 changed files with 6 additions and 2 deletions

View File

@ -62,7 +62,11 @@ CurvesGeometry::CurvesGeometry(const int point_num, const int curve_num)
this->point_num,
ATTR_POSITION.c_str());
this->curve_offsets = (int *)MEM_calloc_arrayN(this->curve_num + 1, sizeof(int), __func__);
this->curve_offsets = (int *)MEM_malloc_arrayN(this->curve_num + 1, sizeof(int), __func__);
#ifdef DEBUG
this->offsets_for_write().fill(-1);
#endif
this->offsets_for_write().first() = 0;
this->update_customdata_pointers();
@ -84,7 +88,7 @@ static void copy_curves_geometry(CurvesGeometry &dst, const CurvesGeometry &src)
CustomData_copy(&src.curve_data, &dst.curve_data, CD_MASK_ALL, CD_DUPLICATE, dst.curve_num);
MEM_SAFE_FREE(dst.curve_offsets);
dst.curve_offsets = (int *)MEM_calloc_arrayN(dst.point_num + 1, sizeof(int), __func__);
dst.curve_offsets = (int *)MEM_malloc_arrayN(dst.point_num + 1, sizeof(int), __func__);
dst.offsets_for_write().copy_from(src.offsets());
dst.tag_topology_changed();