From 3ec169527372524b638b6857d62a49e14f15f54c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 13 Feb 2016 17:45:41 +1100 Subject: Sculpt: avoid double-hash for pbvh building Gives minor speedup entering sculpt mode and with undo. --- source/blender/blenkernel/intern/pbvh.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'source/blender/blenkernel/intern') diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c index e89873a8a1f..2defda16313 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; -- cgit v1.2.3