Commit: ba0d376e260ba17c7e9f201a501b71de2782b4a3
Author: Ankit Meel
Date:   Fri Aug 14 01:29:11 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rBba0d376e260ba17c7e9f201a501b71de2782b4a3

Use function pointer; remove redundant variables.

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

M       source/blender/io/wavefront_obj/intern/wavefront_obj_ex_file_writer.cc
M       source/blender/io/wavefront_obj/intern/wavefront_obj_ex_file_writer.hh
M       source/blender/io/wavefront_obj/intern/wavefront_obj_ex_mesh.cc
M       source/blender/io/wavefront_obj/intern/wavefront_obj_ex_mesh.hh

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

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 2e5c8a1057c..c9fda3f6f81 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
@@ -55,6 +55,7 @@ void OBJWriter::write_vert_uv_normal_indices(Span<uint> 
vert_indices,
  * Write one line of polygon indices as f v1//vn1 v2//vn2 ... .
  */
 void OBJWriter::write_vert_normal_indices(Span<uint> vert_indices,
+                                          Span<uint> uv_indices,
                                           Span<uint> normal_indices,
                                           const MPoly &poly_to_write) const
 {
@@ -73,6 +74,7 @@ void OBJWriter::write_vert_normal_indices(Span<uint> 
vert_indices,
  */
 void OBJWriter::write_vert_uv_indices(Span<uint> vert_indices,
                                       Span<uint> uv_indices,
+                                      Span<uint> normal_indices,
                                       const MPoly &poly_to_write) const
 {
   fprintf(outfile_, "f");
@@ -88,7 +90,10 @@ void OBJWriter::write_vert_uv_indices(Span<uint> 
vert_indices,
 /**
  *  Write one line of polygon indices as f v1 v2 ... .
  */
-void OBJWriter::write_vert_indices(Span<uint> vert_indices, const MPoly 
&poly_to_write) const
+void OBJWriter::write_vert_indices(Span<uint> vert_indices,
+                                   Span<uint> uv_indices,
+                                   Span<uint> normal_indices,
+                                   const MPoly &poly_to_write) const
 {
   fprintf(outfile_, "f");
   for (uint j = 0; j < poly_to_write.totloop; j++) {
@@ -302,60 +307,42 @@ void OBJWriter::write_poly_elements(const OBJMesh 
&obj_mesh_data,
   /* -1 has no significant value, it could have been any negative number. */
   short last_face_mat_nr = -1;
 
+  void (OBJWriter::*func_vert_uv_normal_indices)(Span<uint> vert_indices,
+                                                 Span<uint> uv_indices,
+                                                 Span<uint> normal_indices,
+                                                 const MPoly &poly_to_write) 
const = nullptr;
   if (export_params_.export_normals) {
     if (export_params_.export_uv && (obj_mesh_data.tot_uv_vertices() > 0)) {
       /* Write both normals and UV indices. */
-      for (uint i = 0; i < obj_mesh_data.tot_polygons(); i++) {
-        obj_mesh_data.calc_poly_vertex_indices(i, vertex_indices);
-        obj_mesh_data.calc_poly_normal_indices(i, normal_indices);
-        const MPoly &poly_to_write = obj_mesh_data.get_ith_poly(i);
-
-        write_smooth_group(obj_mesh_data, last_face_smooth_group, i);
-        write_vertex_group(obj_mesh_data, last_face_vertex_group, i);
-        write_poly_material(obj_mesh_data, i, last_face_mat_nr);
-        write_vert_uv_normal_indices(vertex_indices, uv_indices[i], 
normal_indices, poly_to_write);
-      }
+      func_vert_uv_normal_indices = &OBJWriter::write_vert_uv_normal_indices;
     }
     else {
       /* Write normals indices. */
-      for (uint i = 0; i < obj_mesh_data.tot_polygons(); i++) {
-        obj_mesh_data.calc_poly_vertex_indices(i, vertex_indices);
-        obj_mesh_data.calc_poly_normal_indices(i, normal_indices);
-        const MPoly &poly_to_write = obj_mesh_data.get_ith_poly(i);
-
-        write_smooth_group(obj_mesh_data, last_face_smooth_group, i);
-        write_vertex_group(obj_mesh_data, last_face_vertex_group, i);
-        write_poly_material(obj_mesh_data, i, last_face_mat_nr);
-        write_vert_normal_indices(vertex_indices, normal_indices, 
poly_to_write);
-      }
+      func_vert_uv_normal_indices = &OBJWriter::write_vert_normal_indices;
     }
   }
   else {
     /* Write UV indices. */
     if (export_params_.export_uv && (obj_mesh_data.tot_uv_vertices() > 0)) {
-      for (uint i = 0; i < obj_mesh_data.tot_polygons(); i++) {
-        obj_mesh_data.calc_poly_vertex_indices(i, vertex_indices);
-        const MPoly &poly_to_write = obj_mesh_data.get_ith_poly(i);
-
-        write_smooth_group(obj_mesh_data, last_face_smooth_group, i);
-        write_vertex_group(obj_mesh_data, last_face_vertex_group, i);
-        write_poly_material(obj_mesh_data, i, last_face_mat_nr);
-        write_vert_uv_indices(vertex_indices, uv_indices[i], poly_to_write);
-      }
+      func_vert_uv_normal_indices = &OBJWriter::write_vert_uv_indices;
     }
     else {
       /* Write neither normals nor UV indices. */
-      for (uint i = 0; i < obj_mesh_data.tot_polygons(); i++) {
-        obj_mesh_data.calc_poly_vertex_indices(i, vertex_indices);
-        const MPoly &poly_to_write = obj_mesh_data.get_ith_poly(i);
-
-        write_smooth_group(obj_mesh_data, last_face_smooth_group, i);
-        write_vertex_group(obj_mesh_data, last_face_vertex_group, i);
-        write_poly_material(obj_mesh_data, i, last_face_mat_nr);
-        write_vert_indices(vertex_indices, poly_to_write);
-      }
+      func_vert_uv_normal_indices = &OBJWriter::write_vert_indices;
     }
   }
+
+  for (uint i = 0; i < obj_mesh_data.tot_polygons(); i++) {
+    obj_mesh_data.calc_poly_vertex_indices(i, vertex_indices);
+    obj_mesh_data.calc_poly_normal_indices(i, normal_indices);
+    const MPoly &poly_to_write = obj_mesh_data.get_ith_poly(i);
+
+    write_smooth_group(obj_mesh_data, last_face_smooth_group, i);
+    write_vertex_group(obj_mesh_data, last_face_vertex_group, i);
+    write_poly_material(obj_mesh_data, i, last_face_mat_nr);
+    (this->*func_vert_uv_normal_indices)(
+        vertex_indices, uv_indices[i], normal_indices, poly_to_write);
+  }
 }
 
 /**
diff --git 
a/source/blender/io/wavefront_obj/intern/wavefront_obj_ex_file_writer.hh 
b/source/blender/io/wavefront_obj/intern/wavefront_obj_ex_file_writer.hh
index 0935fb3cd11..0e64c5d9c22 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_ex_file_writer.hh
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_ex_file_writer.hh
@@ -81,12 +81,17 @@ class OBJWriter {
   void update_index_offsets(const OBJMesh &obj_mesh_data);
 
  private:
-  void write_vert_indices(Span<uint> vert_indices, const MPoly &poly_to_write) 
const;
+  void write_vert_indices(Span<uint> vert_indices,
+                          Span<uint> uv_indices,
+                          Span<uint> normal_indices,
+                          const MPoly &poly_to_write) const;
   void write_vert_normal_indices(Span<uint> vert_indices,
+                                 Span<uint> uv_indices,
                                  Span<uint> normal_indices,
                                  const MPoly &poly_to_write) const;
   void write_vert_uv_indices(Span<uint> vert_indices,
                              Span<uint> uv_indices,
+                             Span<uint> normal_indices,
                              const MPoly &poly_to_write) const;
   void write_vert_uv_normal_indices(Span<uint> vert_indices,
                                     Span<uint> uv_indices,
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 014c02f9147..858d5cbf317 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
@@ -70,21 +70,15 @@ OBJMesh::OBJMesh(Depsgraph *depsgraph, const 
OBJExportParams &export_params, Obj
       if (export_params_.export_triangulated_mesh) {
         triangulate_mesh_eval();
       }
-      tot_poly_normals_ = export_mesh_eval_->totpoly;
-      if (tot_poly_normals_ <= 0) {
-        tot_poly_normals_ = 0;
-      }
       break;
     }
     case OB_CURVE: {
-      tot_poly_normals_ = 0;
       break;
     }
     default: {
       break;
     }
   }
-  tot_vertices_ = export_mesh_eval_->totvert;
   store_world_axes_transform();
 }
 
@@ -153,12 +147,12 @@ void OBJMesh::store_world_axes_transform()
 
 uint OBJMesh::tot_vertices() const
 {
-  return tot_vertices_;
+  return export_mesh_eval_->totvert;
 }
 
 uint OBJMesh::tot_polygons() const
 {
-  return tot_poly_normals_;
+  return export_mesh_eval_->totface;
 }
 
 uint OBJMesh::tot_uv_vertices() const
@@ -325,7 +319,7 @@ void 
OBJMesh::store_uv_coords_and_indices(Vector<std::array<float, 2>> &r_uv_coo
       if (uv_vert->separate) {
         tot_uv_vertices_ += 1;
       }
-      if (UNLIKELY(tot_uv_vertices_ == 0)) {
+      if (tot_uv_vertices_ == 0) {
         return;
       }
       const uint vertices_in_poly = (uint)mpoly[uv_vert->poly_index].totloop;
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 2ece3fd7474..a1d3ebe6dc7 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
@@ -56,14 +56,6 @@ class OBJMesh : NonMovable, NonCopyable {
    */
   float world_and_axes_transform_[4][4] = {};
 
-  /**
-   * Total vertices in a mesh.
-   */
-  uint tot_vertices_ = 0;
-  /**
-   * Total polygons (and thus normals) in a mesh.
-   */
-  uint tot_poly_normals_ = 0;
   /**
    * Total UV vertices in a mesh's texture map.
    */

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to