[Bf-blender-cvs] [5217d2b] master: Use BKE_edgehash_ensure_p where possible

Campbell Barton noreply at git.blender.org
Tue Apr 7 03:05:07 CEST 2015


Commit: 5217d2bc0e29695bea74950ff05a9215a85ff703
Author: Campbell Barton
Date:   Tue Apr 7 10:53:58 2015 +1000
Branches: master
https://developer.blender.org/rB5217d2bc0e29695bea74950ff05a9215a85ff703

Use BKE_edgehash_ensure_p where possible

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

M	source/blender/blenkernel/intern/cdderivedmesh.c
M	source/blender/blenkernel/intern/mesh_validate.c
M	source/blender/blenlib/intern/polyfill2d_beautify.c
M	source/blender/bmesh/intern/bmesh_mesh_validate.c
M	source/blender/editors/armature/meshlaplacian.c

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

diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c
index 1c2c6eb..bd5ee4b 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -2545,16 +2545,16 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap, const int
 		const unsigned int v1 = (vtargetmap[med->v1] != -1) ? vtargetmap[med->v1] : med->v1;
 		const unsigned int v2 = (vtargetmap[med->v2] != -1) ? vtargetmap[med->v2] : med->v2;
 		if (LIKELY(v1 != v2)) {
-			void **eh_p = BLI_edgehash_lookup_p(ehash, v1, v2);
+			void **val_p;
 
-			if (eh_p) {
-				newe[i] = GET_INT_FROM_POINTER(*eh_p);
+			if (BLI_edgehash_ensure_p(ehash, v1, v2, &val_p)) {
+				newe[i] = GET_INT_FROM_POINTER(*val_p);
 			}
 			else {
 				STACK_PUSH(olde, i);
 				STACK_PUSH(medge, *med);
 				newe[i] = c;
-				BLI_edgehash_insert(ehash, v1, v2, SET_INT_IN_POINTER(c));
+				*val_p = SET_INT_IN_POINTER(c);
 				c++;
 			}
 		}
diff --git a/source/blender/blenkernel/intern/mesh_validate.c b/source/blender/blenkernel/intern/mesh_validate.c
index 7de993e..f758bcd 100644
--- a/source/blender/blenkernel/intern/mesh_validate.c
+++ b/source/blender/blenkernel/intern/mesh_validate.c
@@ -1475,8 +1475,9 @@ void BKE_mesh_calc_edges(Mesh *mesh, bool update, const bool select)
 		int j, v_prev = (l + (mp->totloop - 1))->v;
 		for (j = 0; j < mp->totloop; j++, l++) {
 			if (v_prev != l->v) {
-				if (!BLI_edgehash_haskey(eh, v_prev, l->v)) {
-					BLI_edgehash_insert(eh, v_prev, l->v, NULL);
+				void **val_p;
+				if (!BLI_edgehash_ensure_p(eh, v_prev, l->v, &val_p)) {
+					*val_p = NULL;
 				}
 			}
 			v_prev = l->v;
diff --git a/source/blender/blenlib/intern/polyfill2d_beautify.c b/source/blender/blenlib/intern/polyfill2d_beautify.c
index ba71f52..46f9251 100644
--- a/source/blender/blenlib/intern/polyfill2d_beautify.c
+++ b/source/blender/blenlib/intern/polyfill2d_beautify.c
@@ -430,17 +430,19 @@ void BLI_polyfill_beautify(
 			}
 
 			if (!is_boundary_edge(e_pair[0], e_pair[1], coord_last)) {
-				struct PolyEdge *e = BLI_edgehash_lookup(ehash, e_pair[0], e_pair[1]);
-				if (e == NULL) {
+				struct PolyEdge *e;
+				void **val_p;
+
+				if (!BLI_edgehash_ensure_p(ehash, e_pair[0], e_pair[1], &val_p)) {
 					e = &edges[edges_tot_used++];
-					BLI_edgehash_insert(ehash, e_pair[0], e_pair[1], e);
+					*val_p = e;
 					memcpy(e->verts, e_pair, sizeof(e->verts));
 #ifndef NDEBUG
 					e->faces[!e_index] = (unsigned int)-1;
 #endif
 				}
 				else {
-
+					e = *val_p;
 					/* ensure each edge only ever has 2x users */
 #ifndef NDEBUG
 					BLI_assert(e->faces[e_index] == (unsigned int)-1);
diff --git a/source/blender/bmesh/intern/bmesh_mesh_validate.c b/source/blender/bmesh/intern/bmesh_mesh_validate.c
index 3a7a4f8..494da3b 100644
--- a/source/blender/bmesh/intern/bmesh_mesh_validate.c
+++ b/source/blender/bmesh/intern/bmesh_mesh_validate.c
@@ -86,20 +86,19 @@ bool BM_mesh_validate(BMesh *bm)
 
 	/* check edges */
 	BM_ITER_MESH_INDEX (e, &iter, bm, BM_EDGES_OF_MESH, i) {
-		BMEdge *e_other;
+		void **val_p;
 
 		if (e->v1 == e->v2) {
 			ERRMSG("edge %d: duplicate index: %d", i, BM_elem_index_get(e->v1));
 		}
 
-
 		/* build edgehash at the same time */
-		e_other = BLI_edgehash_lookup(edge_hash, BM_elem_index_get(e->v1), BM_elem_index_get(e->v2));
-		if (e_other) {
+		if (BLI_edgehash_ensure_p(edge_hash, BM_elem_index_get(e->v1), BM_elem_index_get(e->v2), &val_p)) {
+			BMEdge *e_other = *val_p;
 			ERRMSG("edge %d, %d: are duplicates", i, BM_elem_index_get(e_other));
 		}
 		else {
-			BLI_edgehash_insert(edge_hash, BM_elem_index_get(e->v1), BM_elem_index_get(e->v2), e);
+			*val_p = e;
 		}
 	}
 
diff --git a/source/blender/editors/armature/meshlaplacian.c b/source/blender/editors/armature/meshlaplacian.c
index b7d14e0..fa774b0 100644
--- a/source/blender/editors/armature/meshlaplacian.c
+++ b/source/blender/editors/armature/meshlaplacian.c
@@ -127,12 +127,12 @@ struct LaplacianSystem {
 
 static void laplacian_increase_edge_count(EdgeHash *edgehash, int v1, int v2)
 {
-	void **p = BLI_edgehash_lookup_p(edgehash, v1, v2);
+	void **p;
 
-	if (p)
+	if (BLI_edgehash_ensure_p(edgehash, v1, v2, &p))
 		*p = (void *)((intptr_t)*p + (intptr_t)1);
 	else
-		BLI_edgehash_insert(edgehash, v1, v2, (void *)(intptr_t)1);
+		*p = (void *)((intptr_t)1);
 }
 
 static int laplacian_edge_count(EdgeHash *edgehash, int v1, int v2)




More information about the Bf-blender-cvs mailing list