[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [57448] trunk/blender/source/blender/ blenkernel: code cleanup: reduce pointer indirection for mesh-map creation functions.

Campbell Barton ideasman42 at gmail.com
Fri Jun 14 08:34:38 CEST 2013


Revision: 57448
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57448
Author:   campbellbarton
Date:     2013-06-14 06:34:37 +0000 (Fri, 14 Jun 2013)
Log Message:
-----------
code cleanup: reduce pointer indirection for mesh-map creation functions.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_mesh.h
    trunk/blender/source/blender/blenkernel/intern/mesh.c

Modified: trunk/blender/source/blender/blenkernel/BKE_mesh.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_mesh.h	2013-06-14 06:15:30 UTC (rev 57447)
+++ trunk/blender/source/blender/blenkernel/BKE_mesh.h	2013-06-14 06:34:37 UTC (rev 57448)
@@ -303,11 +303,11 @@
 	int index;
 } IndexNode;
 
-void BKE_mesh_vert_poly_map_create(MeshElemMap **map, int **mem,
+void BKE_mesh_vert_poly_map_create(MeshElemMap **r_map, int **r_mem,
                                    const struct MPoly *mface, const struct MLoop *mloop,
                                    int totvert, int totface, int totloop);
 
-void BKE_mesh_vert_edge_map_create(MeshElemMap **map, int **mem,
+void BKE_mesh_vert_edge_map_create(MeshElemMap **r_map, int **r_mem,
                                    const struct MEdge *medge, int totvert, int totedge);
 
 /* vertex level transformations & checks (no derived mesh) */

Modified: trunk/blender/source/blender/blenkernel/intern/mesh.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/mesh.c	2013-06-14 06:15:30 UTC (rev 57447)
+++ trunk/blender/source/blender/blenkernel/intern/mesh.c	2013-06-14 06:34:37 UTC (rev 57448)
@@ -2441,32 +2441,30 @@
 /* Generates a map where the key is the vertex and the value is a list
  * of polys that use that vertex as a corner. The lists are allocated
  * from one memory pool. */
-void BKE_mesh_vert_poly_map_create(MeshElemMap **map, int **mem,
+void BKE_mesh_vert_poly_map_create(MeshElemMap **r_map, int **r_mem,
                                    const MPoly *mpoly, const MLoop *mloop,
                                    int totvert, int totpoly, int totloop)
 {
+	MeshElemMap *map = MEM_callocN(sizeof(MeshElemMap) * totvert, "vert poly map");
+	int *indices = MEM_mallocN(sizeof(int) * totloop, "vert poly map mem");
+
 	int i, j;
-	int *indices;
 
-	(*map) = MEM_callocN(sizeof(MeshElemMap) * totvert, "vert poly map");
-	(*mem) = MEM_mallocN(sizeof(int) * totloop, "vert poly map mem");
-
 	/* Count number of polys for each vertex */
 	for (i = 0; i < totpoly; i++) {
 		const MPoly *p = &mpoly[i];
 		
 		for (j = 0; j < p->totloop; j++)
-			(*map)[mloop[p->loopstart + j].v].count++;
+			map[mloop[p->loopstart + j].v].count++;
 	}
 
 	/* Assign indices mem */
-	indices = (*mem);
 	for (i = 0; i < totvert; i++) {
-		(*map)[i].indices = indices;
-		indices += (*map)[i].count;
+		map[i].indices = indices;
+		indices += map[i].count;
 
 		/* Reset 'count' for use as index in last loop */
-		(*map)[i].count = 0;
+		map[i].count = 0;
 	}
 		
 	/* Find the users */
@@ -2476,49 +2474,54 @@
 		for (j = 0; j < p->totloop; j++) {
 			int v = mloop[p->loopstart + j].v;
 			
-			(*map)[v].indices[(*map)[v].count] = i;
-			(*map)[v].count++;
+			map[v].indices[map[v].count] = i;
+			map[v].count++;
 		}
 	}
+
+	*r_map = map;
+	*r_mem = indices;
 }
 
 /* Generates a map where the key is the vertex and the value is a list
  * of edges that use that vertex as an endpoint. The lists are allocated
  * from one memory pool. */
-void BKE_mesh_vert_edge_map_create(MeshElemMap **map, int **mem,
+void BKE_mesh_vert_edge_map_create(MeshElemMap **r_map, int **r_mem,
                                    const MEdge *medge, int totvert, int totedge)
 {
-	int i, *indices;
+	MeshElemMap *map = MEM_callocN(sizeof(MeshElemMap) * totvert, "vert-edge map");
+	int *indices = MEM_mallocN(sizeof(int) * totedge * 2, "vert-edge map mem");
 
-	(*map) = MEM_callocN(sizeof(MeshElemMap) * totvert, "vert-edge map");
-	(*mem) = MEM_mallocN(sizeof(int) * totedge * 2, "vert-edge map mem");
+	int i;
 
 	/* Count number of edges for each vertex */
 	for (i = 0; i < totedge; i++) {
-		(*map)[medge[i].v1].count++;
-		(*map)[medge[i].v2].count++;
+		map[medge[i].v1].count++;
+		map[medge[i].v2].count++;
 	}
 
 	/* Assign indices mem */
-	indices = (*mem);
 	for (i = 0; i < totvert; i++) {
-		(*map)[i].indices = indices;
-		indices += (*map)[i].count;
+		map[i].indices = indices;
+		indices += map[i].count;
 
 		/* Reset 'count' for use as index in last loop */
-		(*map)[i].count = 0;
+		map[i].count = 0;
 	}
 		
 	/* Find the users */
 	for (i = 0; i < totedge; i++) {
 		const int v[2] = {medge[i].v1, medge[i].v2};
 
-		(*map)[v[0]].indices[(*map)[v[0]].count] = i;
-		(*map)[v[1]].indices[(*map)[v[1]].count] = i;
+		map[v[0]].indices[map[v[0]].count] = i;
+		map[v[1]].indices[map[v[1]].count] = i;
 		
-		(*map)[v[0]].count++;
-		(*map)[v[1]].count++;
+		map[v[0]].count++;
+		map[v[1]].count++;
 	}
+
+	*r_map = map;
+	*r_mem = indices;
 }
 
 void BKE_mesh_loops_to_mface_corners(CustomData *fdata, CustomData *ldata,




More information about the Bf-blender-cvs mailing list