[Bf-blender-cvs] [3ec1695] master: Sculpt: avoid double-hash for pbvh building

Campbell Barton noreply at git.blender.org
Sat Feb 13 09:08:02 CET 2016


Commit: 3ec169527372524b638b6857d62a49e14f15f54c
Author: Campbell Barton
Date:   Sat Feb 13 17:45:41 2016 +1100
Branches: master
https://developer.blender.org/rB3ec169527372524b638b6857d62a49e14f15f54c

Sculpt: avoid double-hash for pbvh building

Gives minor speedup entering sculpt mode and with undo.

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

M	source/blender/blenkernel/intern/pbvh.c

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

diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index e89873a..2defda1 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -246,22 +246,19 @@ static int map_insert_vert(PBVH *bvh, GHash *map,
 	void *key, **value_p;
 
 	key = SET_INT_IN_POINTER(vertex);
-	value_p = BLI_ghash_lookup_p(map, key);
-
-	if (value_p == NULL) {
-		void *value;
-		if (BLI_BITMAP_TEST(bvh->vert_bitmap, vertex)) {
-			value = SET_INT_IN_POINTER(~(*face_verts));
-			++(*face_verts);
+	if (!BLI_ghash_ensure_p(map, key, &value_p)) {
+		int value_i;
+		if (BLI_BITMAP_TEST(bvh->vert_bitmap, vertex) == 0) {
+			BLI_BITMAP_ENABLE(bvh->vert_bitmap, vertex);
+			value_i = *uniq_verts;
+			(*uniq_verts)++;
 		}
 		else {
-			BLI_BITMAP_ENABLE(bvh->vert_bitmap, vertex);
-			value = SET_INT_IN_POINTER(*uniq_verts);
-			++(*uniq_verts);
+			value_i = ~(*face_verts);
+			(*face_verts)++;
 		}
-		
-		BLI_ghash_insert(map, key, value);
-		return GET_INT_FROM_POINTER(value);
+		*value_p = SET_INT_IN_POINTER(value_i);
+		return value_i;
 	}
 	else {
 		return GET_INT_FROM_POINTER(*value_p);
@@ -502,7 +499,7 @@ static void pbvh_build(PBVH *bvh, BB *cb, BBC *prim_bbc, int totprim)
 		bvh->totprim = totprim;
 		if (bvh->nodes) MEM_freeN(bvh->nodes);
 		if (bvh->prim_indices) MEM_freeN(bvh->prim_indices);
-		bvh->prim_indices = MEM_callocN(sizeof(int) * totprim,
+		bvh->prim_indices = MEM_mallocN(sizeof(int) * totprim,
 		                                "bvh prim indices");
 		for (int i = 0; i < totprim; ++i)
 			bvh->prim_indices[i] = i;




More information about the Bf-blender-cvs mailing list