[Bf-blender-cvs] [ffaa1df4397] soc-2020-io-performance: Cleanup: silence clang-tidy warnings; comments.

Ankit Meel noreply at git.blender.org
Fri Jul 24 21:12:17 CEST 2020


Commit: ffaa1df43971ceec36df55cab645706c5c0927f2
Author: Ankit Meel
Date:   Sat Jul 25 00:05:45 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rBffaa1df43971ceec36df55cab645706c5c0927f2

Cleanup: silence clang-tidy warnings; comments.

Use static_cast wherever applicable.

Pass struct by reference.

Remove unnecessary const qualifiers for primitive types.

Make some member functions static instead.

Remove intermediate non-owning pointers to new class instances.

Remove else in else-after-return.

Initialise variables at definition.

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

M	source/blender/io/wavefront_obj/intern/wavefront_obj_ex_file_writer.cc
M	source/blender/io/wavefront_obj/intern/wavefront_obj_ex_mesh.cc
M	source/blender/io/wavefront_obj/intern/wavefront_obj_ex_mesh.hh
M	source/blender/io/wavefront_obj/intern/wavefront_obj_ex_mtl.cc
M	source/blender/io/wavefront_obj/intern/wavefront_obj_ex_mtl.hh
M	source/blender/io/wavefront_obj/intern/wavefront_obj_ex_nurbs.cc
M	source/blender/io/wavefront_obj/intern/wavefront_obj_ex_nurbs.hh
M	source/blender/io/wavefront_obj/intern/wavefront_obj_exporter.cc
M	source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
M	source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc
M	source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.hh
M	source/blender/io/wavefront_obj/intern/wavefront_obj_im_nurbs.cc
M	source/blender/io/wavefront_obj/intern/wavefront_obj_im_nurbs.hh
M	source/blender/io/wavefront_obj/intern/wavefront_obj_im_objects.cc
M	source/blender/io/wavefront_obj/intern/wavefront_obj_im_objects.hh
M	source/blender/io/wavefront_obj/intern/wavefront_obj_importer.cc

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

diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_ex_file_writer.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj_ex_file_writer.cc
index d96aea16f19..14aa803850c 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_ex_file_writer.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_ex_file_writer.cc
@@ -140,12 +140,10 @@ void OBJWriter::write_mtllib(const char *obj_filepath)
  */
 void OBJWriter::write_object_name(OBJMesh &obj_mesh_data)
 {
-  const char *object_name;
-  object_name = obj_mesh_data.get_object_name();
+  const char *object_name = obj_mesh_data.get_object_name();
 
   if (export_params_.export_object_groups) {
-    const char *object_data_name;
-    object_data_name = obj_mesh_data.get_object_data_name();
+    const char *object_data_name = obj_mesh_data.get_object_data_name();
     fprintf(outfile_, "g %s_%s\n", object_name, object_data_name);
   }
   else {
@@ -213,7 +211,7 @@ void OBJWriter::write_smooth_group(OBJMesh &obj_mesh_data,
   if (!export_params_.export_smooth_groups || !obj_mesh_data.tot_smooth_groups()) {
     return;
   }
-  if ((obj_mesh_data.get_ith_poly(poly_index).flag & ME_SMOOTH) == true) {
+  if (obj_mesh_data.get_ith_poly(poly_index).flag & ME_SMOOTH) {
     int curr_group = obj_mesh_data.ith_smooth_group(poly_index);
     if (curr_group == r_last_face_smooth_group) {
       return;
@@ -251,13 +249,10 @@ void OBJWriter::write_poly_material(OBJMesh &obj_mesh_data,
   /* Whenever a face with a new material is encountered, write its material and group, otherwise
    * pass. */
   if (UNLIKELY(r_last_face_mat_nr == mat_nr)) {
-    const char *mat_name;
-    mat_name = obj_mesh_data.get_object_material_name(mat_nr + 1);
+    const char *mat_name = obj_mesh_data.get_object_material_name(mat_nr + 1);
     if (export_params_.export_material_groups) {
-      const char *object_name;
-      const char *object_data_name;
-      object_name = obj_mesh_data.get_object_name();
-      object_data_name = obj_mesh_data.get_object_data_name();
+      const char *object_name = obj_mesh_data.get_object_name();
+      const char *object_data_name = obj_mesh_data.get_object_data_name();
       fprintf(outfile_, "g %s_%s_%s\n", object_name, object_data_name, mat_name);
     }
     fprintf(outfile_, "usemtl %s\n", mat_name);
@@ -387,16 +382,15 @@ void OBJWriter::write_nurbs_curve(OBJNurbs &obj_nurbs_data)
     int tot_points = nurb->pntsv * nurb->pntsu;
     float point_coord[3];
     for (int point_idx = 0; point_idx < tot_points; point_idx++) {
-      obj_nurbs_data.calc_point_coords(point_coord, point_idx, nurb);
+      obj_nurbs_data.calc_point_coords(nurb, point_idx, point_coord);
       fprintf(outfile_, "v %f %f %f\n", point_coord[0], point_coord[1], point_coord[2]);
     }
 
-    const char *nurbs_name;
-    nurbs_name = obj_nurbs_data.get_curve_name();
-    int nurbs_degree;
+    const char *nurbs_name = obj_nurbs_data.get_curve_name();
+    int nurbs_degree = 0;
     /* Number of vertices in the curve + degree of the curve if it is cyclic. */
-    int curv_num;
-    obj_nurbs_data.get_curve_info(nurbs_degree, curv_num, nurb);
+    int curv_num = 0;
+    obj_nurbs_data.get_curve_info(nurb, nurbs_degree, curv_num);
 
     fprintf(outfile_, "g %s\ncstype bspline\ndeg %d\n", nurbs_name, nurbs_degree);
     /**
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_ex_mesh.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj_ex_mesh.cc
index ed7fd1b3959..0dbf5ed9167 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_ex_mesh.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_ex_mesh.cc
@@ -154,22 +154,22 @@ void OBJMesh::store_world_axes_transform()
   copy_v4_v4(world_and_axes_transform_[3], export_object_eval_->obmat[3]);
 }
 
-const uint OBJMesh::tot_vertices()
+uint OBJMesh::tot_vertices() const
 {
   return tot_vertices_;
 }
 
-const uint OBJMesh::tot_polygons()
+uint OBJMesh::tot_polygons() const
 {
   return tot_poly_normals_;
 }
 
-const uint OBJMesh::tot_uv_vertices()
+uint OBJMesh::tot_uv_vertices() const
 {
   return tot_uv_vertices_;
 }
 
-const uint OBJMesh::tot_edges()
+uint OBJMesh::tot_edges() const
 {
   return tot_edges_;
 }
@@ -177,7 +177,7 @@ const uint OBJMesh::tot_edges()
 /**
  * Total materials in the object to export.
  */
-const short OBJMesh::tot_col()
+short OBJMesh::tot_col() const
 {
   return export_mesh_eval_->totcol;
 }
@@ -185,7 +185,7 @@ const short OBJMesh::tot_col()
 /**
  * Total smooth groups in the object to export.
  */
-const uint OBJMesh::tot_smooth_groups()
+uint OBJMesh::tot_smooth_groups() const
 {
   return tot_smooth_groups_;
 }
@@ -193,7 +193,7 @@ const uint OBJMesh::tot_smooth_groups()
 /**
  * Return smooth group of the polygon at the given index.
  */
-const int OBJMesh::ith_smooth_group(int poly_index)
+int OBJMesh::ith_smooth_group(int poly_index) const
 {
   BLI_assert(poly_smooth_groups_);
   return poly_smooth_groups_[poly_index];
@@ -268,9 +268,9 @@ const char *OBJMesh::get_object_material_name(short mat_nr)
 /**
  * Calculate coordinates of a vertex at the given index.
  */
-void OBJMesh::calc_vertex_coords(float r_coords[3], uint point_index)
+void OBJMesh::calc_vertex_coords(float r_coords[3], uint vert_index)
 {
-  copy_v3_v3(r_coords, export_mesh_eval_->mvert[point_index].co);
+  copy_v3_v3(r_coords, export_mesh_eval_->mvert[vert_index].co);
   mul_m4_v3(world_and_axes_transform_, r_coords);
   mul_v3_fl(r_coords, export_params_.scaling_factor);
 }
@@ -298,7 +298,8 @@ void OBJMesh::store_uv_coords_and_indices(Vector<std::array<float, 2>> &r_uv_coo
   const MLoop *mloop = export_mesh_eval_->mloop;
   const uint totpoly = export_mesh_eval_->totpoly;
   const uint totvert = export_mesh_eval_->totvert;
-  const MLoopUV *mloopuv = (MLoopUV *)CustomData_get_layer(&export_mesh_eval_->ldata, CD_MLOOPUV);
+  const MLoopUV *mloopuv = static_cast<MLoopUV *>(
+      CustomData_get_layer(&export_mesh_eval_->ldata, CD_MLOOPUV));
   if (!mloopuv) {
     tot_uv_vertices_ = 0;
     return;
@@ -399,26 +400,26 @@ const char *OBJMesh::get_poly_deform_group_name(const MPoly &mpoly, short &r_las
   const MLoop *mloop = &export_mesh_eval_->mloop[mpoly.loopstart];
   /* Indices of the vector index into deform groups of an object; values are the number of vertex
    * members in one deform group. */
-  Vector<int> deform_group_members;
+  Vector<int> deform_group_members{};
   uint tot_deform_groups = BLI_listbase_count(&export_object_eval_->defbase);
   deform_group_members.resize(tot_deform_groups, 0);
   /* Whether at least one vertex in the polygon belongs to any group. */
   bool found_group = false;
 
-  const MDeformVert *dvert_orig = (MDeformVert *)CustomData_get_layer(&export_mesh_eval_->vdata,
-                                                                      CD_MDEFORMVERT);
+  const MDeformVert *dvert_orig = static_cast<MDeformVert *>(
+      CustomData_get_layer(&export_mesh_eval_->vdata, CD_MDEFORMVERT));
   if (!dvert_orig) {
     return nullptr;
   }
 
-  const MDeformWeight *curr_weight;
-  const MDeformVert *dvert;
+  const MDeformWeight *curr_weight = nullptr;
+  const MDeformVert *dvert = nullptr;
   for (uint loop_index = 0; loop_index < mpoly.totloop; loop_index++) {
     dvert = &dvert_orig[(mloop + loop_index)->v];
     curr_weight = dvert->dw;
     if (curr_weight) {
-      bDeformGroup *vertex_group = (bDeformGroup *)BLI_findlink((&export_object_eval_->defbase),
-                                                                curr_weight->def_nr);
+      bDeformGroup *vertex_group = static_cast<bDeformGroup *>(
+          BLI_findlink((&export_object_eval_->defbase), curr_weight->def_nr));
       if (vertex_group) {
         deform_group_members[curr_weight->def_nr] += 1;
         found_group = true;
@@ -447,7 +448,7 @@ const char *OBJMesh::get_poly_deform_group_name(const MPoly &mpoly, short &r_las
 
   r_last_vertex_group = max_idx;
   const bDeformGroup &vertex_group = *(
-      (bDeformGroup *)BLI_findlink(&export_object_eval_->defbase, max_idx));
+      static_cast<bDeformGroup *>(BLI_findlink(&export_object_eval_->defbase, max_idx)));
 
   return vertex_group.name;
 }
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_ex_mesh.hh b/source/blender/io/wavefront_obj/intern/wavefront_obj_ex_mesh.hh
index 84f195654da..6dad757d76c 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_ex_mesh.hh
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_ex_mesh.hh
@@ -54,24 +54,24 @@ class OBJMesh : NonMovable, NonCopyable {
    * Final transform of an object obtained from export settings (up_axis, forward_axis) and world
    * transform matrix.
    */
-  float world_and_axes_transform_[4][4];
+  float world_and_axes_transform_[4][4] = {};
 
   /**
    * Total vertices in a mesh.
    */
-  uint tot_vertices_;
+  uint tot_vertices_ = 0;
   /**
    * Total polygons (and thus normals) in a mesh.
    */
-  uint tot_poly_normals_;
+  uint tot_poly_normals_ = 0;
   /**
    * Total UV vertices in a mesh's texture map.
    */
-  uint tot_uv_vertices_;
+  uint tot_uv_vertices_ = 0;
   /**
    * Only for curve converted to meshes: total edges in a mesh.
    */
-  uint tot_edges_;
+  uint tot_edges_ = 0;
   /**
    * Total smooth groups in an object.
    */
@@ -85,13 +85,13 @@ class OBJMesh : NonMovable, NonCopyable {
   OBJMesh(Depsgraph *depsgraph, const OBJExportParams &export_params, Object *export_object);
   ~OBJMesh();
 
-  const uint tot_vertices();
-  const uint tot_polygons();
-  const uint tot_uv_vertices();
-  const uint tot_edges();
-  const short tot_col();
-  const uint tot_smooth_groups();
-  const int ith_smooth_group(int poly_index);
+  uint tot_vertices() const;
+  uint tot_polygons() const;
+  uint tot_uv_vertices() const;
+  uint tot_edges() const;
+  short tot_col() const;
+  uint tot_smooth_groups() const;
+  int ith_smooth_group(int poly_index) const;
 
   void ensure_mesh_normals();
   void calc_smooth_groups();
@@ -107,7 +107,7 @@ class OBJMesh : NonMovable, NonCopyable {
   void store_uv_coords_and_indices(Vector<std::array<float, 2>> &r_uv_coords,
                                    Vector<Vector<uint>> &r_uv_indices);
   void ca

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list