[Bf-blender-cvs] [81d75affb18] master: Cleanup: Use const arguments in definition, add helper variable

Hans Goudey noreply at git.blender.org
Wed Aug 3 19:00:47 CEST 2022


Commit: 81d75affb18bad6734e4c8baa0d735bfec0dcc6e
Author: Hans Goudey
Date:   Wed Aug 3 11:58:52 2022 -0500
Branches: master
https://developer.blender.org/rB81d75affb18bad6734e4c8baa0d735bfec0dcc6e

Cleanup: Use const arguments in definition, add helper variable

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

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

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

diff --git a/source/blender/blenkernel/intern/customdata.cc b/source/blender/blenkernel/intern/customdata.cc
index b12eafa9cef..f686f5cca64 100644
--- a/source/blender/blenkernel/intern/customdata.cc
+++ b/source/blender/blenkernel/intern/customdata.cc
@@ -165,7 +165,7 @@ struct LayerTypeInfo {
   void (*initminmax)(void *min, void *max);
   void (*add)(void *data1, const void *data2);
   void (*dominmax)(const void *data1, void *min, void *max);
-  void (*copyvalue)(const void *source, void *dest, const int mixmode, const float mixfactor);
+  void (*copyvalue)(const void *source, void *dest, int mixmode, const float mixfactor);
 
   /** a function to read data from a cdf file */
   bool (*read)(CDataFile *cdf, void *data, int count);
@@ -187,7 +187,7 @@ struct LayerTypeInfo {
 /** \name Callbacks for (#MDeformVert, #CD_MDEFORMVERT)
  * \{ */
 
-static void layerCopy_mdeformvert(const void *source, void *dest, int count)
+static void layerCopy_mdeformvert(const void *source, void *dest, const int count)
 {
   int i, size = sizeof(MDeformVert);
 
@@ -209,7 +209,7 @@ static void layerCopy_mdeformvert(const void *source, void *dest, int count)
   }
 }
 
-static void layerFree_mdeformvert(void *data, int count, int size)
+static void layerFree_mdeformvert(void *data, const int count, const int size)
 {
   for (int i = 0; i < count; i++) {
     MDeformVert *dvert = static_cast<MDeformVert *>(POINTER_OFFSET(data, i * size));
@@ -223,7 +223,7 @@ static void layerFree_mdeformvert(void *data, int count, int size)
 }
 
 /* copy just zeros in this case */
-static void layerCopy_bmesh_elem_py_ptr(const void *UNUSED(source), void *dest, int count)
+static void layerCopy_bmesh_elem_py_ptr(const void *UNUSED(source), void *dest, const int count)
 {
   const int size = sizeof(void *);
 
@@ -240,7 +240,7 @@ void bpy_bm_generic_invalidate(struct BPy_BMGeneric *UNUSED(self))
 }
 #endif
 
-static void layerFree_bmesh_elem_py_ptr(void *data, int count, int size)
+static void layerFree_bmesh_elem_py_ptr(void *data, const int count, const int size)
 {
   for (int i = 0; i < count; i++) {
     void **ptr = (void **)POINTER_OFFSET(data, i * size);
@@ -253,7 +253,7 @@ static void layerFree_bmesh_elem_py_ptr(void *data, int count, int size)
 static void layerInterp_mdeformvert(const void **sources,
                                     const float *weights,
                                     const float *UNUSED(sub_weights),
-                                    int count,
+                                    const int count,
                                     void *dest)
 {
   /* a single linked list of MDeformWeight's
@@ -347,7 +347,7 @@ static void layerInterp_mdeformvert(const void **sources,
 static void layerInterp_normal(const void **sources,
                                const float *weights,
                                const float *UNUSED(sub_weights),
-                               int count,
+                               const int count,
                                void *dest)
 {
   /* NOTE: This is linear interpolation, which is not optimal for vectors.
@@ -355,8 +355,8 @@ static void layerInterp_normal(const void **sources,
    * so for now it will do... */
   float no[3] = {0.0f};
 
-  while (count--) {
-    madd_v3_v3fl(no, (const float *)sources[count], weights[count]);
+  for (const int i : IndexRange(count)) {
+    madd_v3_v3fl(no, (const float *)sources[i], weights[i]);
   }
 
   /* Weighted sum of normalized vectors will **not** be normalized, even if weights are. */
@@ -406,7 +406,7 @@ static void layerCopyValue_normal(const void *source,
 /** \name Callbacks for (#MTFace, #CD_MTFACE)
  * \{ */
 
-static void layerCopy_tface(const void *source, void *dest, int count)
+static void layerCopy_tface(const void *source, void *dest, const int count)
 {
   const MTFace *source_tf = (const MTFace *)source;
   MTFace *dest_tf = (MTFace *)dest;
@@ -415,8 +415,11 @@ static void layerCopy_tface(const void *source, void *dest, int count)
   }
 }
 
-static void layerInterp_tface(
-    const void **sources, const float *weights, const float *sub_weights, int count, void *dest)
+static void layerInterp_tface(const void **sources,
+                              const float *weights,
+                              const float *sub_weights,
+                              const int count,
+                              void *dest)
 {
   MTFace *tf = static_cast<MTFace *>(dest);
   float uv[4][2] = {{0.0f}};
@@ -456,7 +459,7 @@ static void layerSwap_tface(void *data, const int *corner_indices)
   memcpy(tf->uv, uv, sizeof(tf->uv));
 }
 
-static void layerDefault_tface(void *data, int count)
+static void layerDefault_tface(void *data, const int count)
 {
   static MTFace default_tf = {{{0, 0}, {1, 0}, {1, 1}, {0, 1}}};
   MTFace *tf = (MTFace *)data;
@@ -477,7 +480,7 @@ static int layerMaxNum_tface()
 /** \name Callbacks for (#MFloatProperty, #CD_PROP_FLOAT)
  * \{ */
 
-static void layerCopy_propFloat(const void *source, void *dest, int count)
+static void layerCopy_propFloat(const void *source, void *dest, const int count)
 {
   memcpy(dest, source, sizeof(MFloatProperty) * count);
 }
@@ -485,7 +488,7 @@ static void layerCopy_propFloat(const void *source, void *dest, int count)
 static void layerInterp_propFloat(const void **sources,
                                   const float *weights,
                                   const float *UNUSED(sub_weights),
-                                  int count,
+                                  const int count,
                                   void *dest)
 {
   float result = 0.0f;
@@ -520,7 +523,7 @@ static bool layerValidate_propFloat(void *data, const uint totitems, const bool
 /** \name Callbacks for (#MIntProperty, #CD_PROP_INT32)
  * \{ */
 
-static void layerCopy_propInt(const void *source, void *dest, int count)
+static void layerCopy_propInt(const void *source, void *dest, const int count)
 {
   memcpy(dest, source, sizeof(MIntProperty) * count);
 }
@@ -528,7 +531,7 @@ static void layerCopy_propInt(const void *source, void *dest, int count)
 static void layerInterp_propInt(const void **sources,
                                 const float *weights,
                                 const float *UNUSED(sub_weights),
-                                int count,
+                                const int count,
                                 void *dest)
 {
   float result = 0.0f;
@@ -547,7 +550,7 @@ static void layerInterp_propInt(const void **sources,
 /** \name Callbacks for (#MStringProperty, #CD_PROP_STRING)
  * \{ */
 
-static void layerCopy_propString(const void *source, void *dest, int count)
+static void layerCopy_propString(const void *source, void *dest, const int count)
 {
   memcpy(dest, source, sizeof(MStringProperty) * count);
 }
@@ -558,7 +561,7 @@ static void layerCopy_propString(const void *source, void *dest, int count)
 /** \name Callbacks for (#OrigSpaceFace, #CD_ORIGSPACE)
  * \{ */
 
-static void layerCopy_origspace_face(const void *source, void *dest, int count)
+static void layerCopy_origspace_face(const void *source, void *dest, const int count)
 {
   const OrigSpaceFace *source_tf = (const OrigSpaceFace *)source;
   OrigSpaceFace *dest_tf = (OrigSpaceFace *)dest;
@@ -568,8 +571,11 @@ static void layerCopy_origspace_face(const void *source, void *dest, int count)
   }
 }
 
-static void layerInterp_origspace_face(
-    const void **sources, const float *weights, const float *sub_weights, int count, void *dest)
+static void layerInterp_origspace_face(const void **sources,
+                                       const float *weights,
+                                       const float *sub_weights,
+                                       const int count,
+                                       void *dest)
 {
   OrigSpaceFace *osf = static_cast<OrigSpaceFace *>(dest);
   float uv[4][2] = {{0.0f}};
@@ -606,7 +612,7 @@ static void layerSwap_origspace_face(void *data, const int *corner_indices)
   memcpy(osf->uv, uv, sizeof(osf->uv));
 }
 
-static void layerDefault_origspace_face(void *data, int count)
+static void layerDefault_origspace_face(void *data, const int count)
 {
   static OrigSpaceFace default_osf = {{{0, 0}, {1, 0}, {1, 1}, {0, 1}}};
   OrigSpaceFace *osf = (OrigSpaceFace *)data;
@@ -652,7 +658,7 @@ static void layerSwap_mdisps(void *data, const int *ci)
   }
 }
 
-static void layerCopy_mdisps(const void *source, void *dest, int count)
+static void layerCopy_mdisps(const void *source, void *dest, const int count)
 {
   const MDisps *s = static_cast<const MDisps *>(source);
   MDisps *d = static_cast<MDisps *>(dest);
@@ -673,7 +679,7 @@ static void layerCopy_mdisps(const void *source, void *dest, int count)
   }
 }
 
-static void layerFree_mdisps(void *data, int count, int UNUSED(size))
+static void layerFree_mdisps(void *data, const int count, const int UNUSED(size))
 {
   MDisps *d = static_cast<MDisps *>(data);
 
@@ -691,7 +697,7 @@ static void layerFree_mdisps(void *data, int count, int UNUSED(size))
   }
 }
 
-static bool layerRead_mdisps(CDataFile *cdf, void *data, int count)
+static bool layerRead_mdisps(CDataFile *cdf, void *data, const int count)
 {
   MDisps *d = static_cast<MDisps *>(data);
 
@@ -709,7 +715,7 @@ static bool layerRead_mdisps(CDataFile *cdf, void *data, int count)
   return true;
 }
 
-static bool layerWrite_mdisps(CDataFile *cdf, const void *data, int count)
+static bool layerWrite_mdisps(CDataFile *cdf, const void *data, const int count)
 {
   const MDisps *d = static_cast<const MDisps *>(data);
 
@@ -723,7 +729,7 @@ static bool layerWrite_mdisps(CDataFile *cdf, const void *data, int count)
   return true;
 }
 
-static size_t layerFilesize_mdisps(CDataFile *UNUSED(cdf), const void *data, int count)
+static size_t layerFilesize_mdisps(CDataFile *UNUSED(cdf), const void *data, const int count)
 {
   const MDisps *d = static_cast<const MDisps *>(data);
   size_t size = 0;
@@ -762,7 +768,7 @@ static void layerInterp_paint_mask(const void **sources,
 /** \name Callbacks for (#GridPaintMask, #CD_GRID_PAINT_MASK)
  * \{ */
 
-static void layerCopy_grid_paint_mask(const void *source, void *dest, int count)
+static void layerCopy_grid_paint_mask(const void 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list