[Bf-blender-cvs] [37d59dbc8cf] soc-2020-io-performance: Cleanup: Rename variables, use {} initialisation.

Ankit Meel noreply at git.blender.org
Fri Jul 17 19:47:12 CEST 2020


Commit: 37d59dbc8cfb79df0f143c513fd4fad1153b9578
Author: Ankit Meel
Date:   Fri Jul 17 22:55:21 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rB37d59dbc8cfb79df0f143c513fd4fad1153b9578

Cleanup: Rename variables, use {} initialisation.

`{}` syntax would help catch when the C++ containers size() function
changes to `int64_t` since initialiser lists don't allow narrowing variables.

Specify that the strings are `_split`.

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

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_objects.hh

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

diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
index 2526e6866da..9ffcd6194a9 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
@@ -136,9 +136,9 @@ void OBJImporter::parse_and_store(Vector<std::unique_ptr<OBJRawObject>> &list_of
     /* TODO ankitm Check that an object exists. */
     else if (line_key == "v") {
       MVert curr_vert;
-      Vector<string> str_vert;
-      split_by_char(s_line.str(), ' ', str_vert);
-      copy_string_to_float(curr_vert.co, str_vert);
+      Vector<string> str_vert_split;
+      split_by_char(s_line.str(), ' ', str_vert_split);
+      copy_string_to_float(curr_vert.co, str_vert_split);
       (*curr_ob)->vertices.append(curr_vert);
     }
     else if (line_key == "vn") {
@@ -146,9 +146,9 @@ void OBJImporter::parse_and_store(Vector<std::unique_ptr<OBJRawObject>> &list_of
     }
     else if (line_key == "vt") {
       MLoopUV curr_tex_vert;
-      Vector<string> str_vert;
-      split_by_char(s_line.str(), ' ', str_vert);
-      copy_string_to_float(curr_tex_vert.uv, str_vert);
+      Vector<string> str_vert_split;
+      split_by_char(s_line.str(), ' ', str_vert_split);
+      copy_string_to_float(curr_tex_vert.uv, str_vert_split);
       curr_tex_vert.flag = false;
       (*curr_ob)->texture_vertices.append(curr_tex_vert);
     }
@@ -189,22 +189,22 @@ void OBJImporter::parse_and_store(Vector<std::unique_ptr<OBJRawObject>> &list_of
         }
         else if (n_slash == 1) {
           /* Case: f v1/vt1 v2/vt2 v3/vt3 . */
-          Vector<std::string> vert_texture;
-          split_by_char(str_corner, '/', vert_texture);
-          copy_string_to_int(&corner.vert_index, {vert_texture[0]});
-          if (vert_texture.size() == 2) {
-            copy_string_to_int(&corner.tex_vert_index, {vert_texture[1]});
+          Vector<string> vert_texture_split;
+          split_by_char(str_corner, '/', vert_texture_split);
+          copy_string_to_int(&corner.vert_index, {vert_texture_split[0]});
+          if (vert_texture_split.size() == 2) {
+            copy_string_to_int(&corner.tex_vert_index, {vert_texture_split[1]});
             (*curr_ob)->tot_uv_verts++;
           }
         }
         else if (n_slash == 2) {
           /* Case: f v1//vn1 v2//vn2 v3//vn3 . */
           /* Case: f v1/vt1/vn1 v2/vt2/vn2 v3/vt3/vn3 . */
-          Vector<std::string> vert_tex_normal;
-          split_by_char(str_corner, '/', vert_tex_normal);
-          copy_string_to_int(&corner.vert_index, {vert_tex_normal[0]});
-          if (vert_tex_normal.size() == 3) {
-            copy_string_to_int(&corner.tex_vert_index, {vert_tex_normal[1]});
+          Vector<string> vert_tex_normal_split;
+          split_by_char(str_corner, '/', vert_tex_normal_split);
+          copy_string_to_int(&corner.vert_index, {vert_tex_normal_split[0]});
+          if (vert_tex_normal_split.size() == 3) {
+            copy_string_to_int(&corner.tex_vert_index, {vert_tex_normal_split[1]});
             (*curr_ob)->tot_uv_verts++;
           }
           /* Discard normals. They'll be calculated on the basis of smooth
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc
index 4c74a8aa897..a5d7e96ad3d 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_mesh.cc
@@ -37,8 +37,8 @@
 namespace blender::io::obj {
 OBJMeshFromRaw::OBJMeshFromRaw(const OBJRawObject &curr_object)
 {
-  uint tot_verts_object = curr_object.vertices.size();
-  uint tot_face_elems = curr_object.face_elements.size();
+  uint tot_verts_object{curr_object.vertices.size()};
+  uint tot_face_elems{curr_object.face_elements.size()};
   mesh_from_ob_.reset(
       BKE_mesh_new_nomain(tot_verts_object, 0, 0, curr_object.tot_loop, tot_face_elems));
 
@@ -46,20 +46,20 @@ OBJMeshFromRaw::OBJMeshFromRaw(const OBJRawObject &curr_object)
     copy_v3_v3(mesh_from_ob_->mvert[i].co, curr_object.vertices[i].co);
   }
 
-  int curr_loop_idx = 0;
-  for (int i = 0; i < tot_face_elems; ++i) {
-    const OBJFaceElem &curr_face = curr_object.face_elements[i];
-    MPoly &mpoly = mesh_from_ob_->mpoly[i];
+  int tot_loop_idx = 0;
+  for (int poly_idx = 0; poly_idx < tot_face_elems; ++poly_idx) {
+    const OBJFaceElem &curr_face = curr_object.face_elements[poly_idx];
+    MPoly &mpoly = mesh_from_ob_->mpoly[poly_idx];
     mpoly.totloop = curr_face.face_corners.size();
-    mpoly.loopstart = curr_loop_idx;
+    mpoly.loopstart = tot_loop_idx;
     if (curr_face.shaded_smooth) {
       mpoly.flag |= ME_SMOOTH;
     }
 
-    for (int j = 0; j < mpoly.totloop; ++j) {
-      MLoop *mloop = &mesh_from_ob_->mloop[curr_loop_idx];
-      mloop->v = curr_face.face_corners[j].vert_index;
-      curr_loop_idx++;
+    for (int loop_of_poly_idx = 0; loop_of_poly_idx < mpoly.totloop; ++loop_of_poly_idx) {
+      MLoop *mloop = &mesh_from_ob_->mloop[tot_loop_idx];
+      tot_loop_idx++;
+      mloop->v = curr_face.face_corners[loop_of_poly_idx].vert_index;
     }
   }
 
@@ -72,7 +72,7 @@ OBJMeshFromRaw::OBJMeshFromRaw(const OBJRawObject &curr_object)
                                                         CD_DUPLICATE,
                                                         mesh_from_ob_->mloopuv,
                                                         curr_object.tot_loop);
-    int loop_idx = 0;
+    int tot_loop_idx = 0;
     for (const OBJFaceElem &curr_face : curr_object.face_elements) {
       for (const OBJFaceCorner &curr_corner : curr_face.face_corners) {
         if (curr_corner.tex_vert_index < 0 ||
@@ -80,8 +80,8 @@ OBJMeshFromRaw::OBJMeshFromRaw(const OBJRawObject &curr_object)
           continue;
         }
         const MLoopUV *mluv_src = &curr_object.texture_vertices[curr_corner.tex_vert_index];
-        copy_v2_v2(mluv_dst[loop_idx].uv, mluv_src->uv);
-        loop_idx++;
+        copy_v2_v2(mluv_dst[tot_loop_idx].uv, mluv_src->uv);
+        tot_loop_idx++;
       }
     }
   }
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_objects.hh b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_objects.hh
index d460f4cf516..bb151f4f7a9 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_objects.hh
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_objects.hh
@@ -50,13 +50,13 @@ class OBJRawObject {
   OBJRawObject(StringRef ob_name) : object_name(ob_name.data()){};
 
   std::string object_name;
-  Vector<MVert> vertices;
-  Vector<MLoopUV> texture_vertices;
-  Vector<OBJFaceElem> face_elements;
+  Vector<MVert> vertices{};
+  Vector<MLoopUV> texture_vertices{};
+  Vector<OBJFaceElem> face_elements{};
   uint tot_normals = 0;
   uint tot_loop = 0;
   uint tot_uv_verts = 0;
-  Vector<std::string> material_name;
+  Vector<std::string> material_name{};
 };
 
 class OBJParentCollection {



More information about the Bf-blender-cvs mailing list