Sculpt: avoid double-hash for pbvh building

Gives minor speedup entering sculpt mode and with undo.
This commit is contained in:
Campbell Barton
2016-02-13 17:45:41 +11:00
parent 2c2d52c2de
commit 3ec1695273

View File

@@ -246,22 +246,19 @@ static int map_insert_vert(PBVH *bvh, GHash *map,
void *key, **value_p; void *key, **value_p;
key = SET_INT_IN_POINTER(vertex); key = SET_INT_IN_POINTER(vertex);
value_p = BLI_ghash_lookup_p(map, key); if (!BLI_ghash_ensure_p(map, key, &value_p)) {
int value_i;
if (value_p == NULL) { if (BLI_BITMAP_TEST(bvh->vert_bitmap, vertex) == 0) {
void *value; BLI_BITMAP_ENABLE(bvh->vert_bitmap, vertex);
if (BLI_BITMAP_TEST(bvh->vert_bitmap, vertex)) { value_i = *uniq_verts;
value = SET_INT_IN_POINTER(~(*face_verts)); (*uniq_verts)++;
++(*face_verts);
} }
else { else {
BLI_BITMAP_ENABLE(bvh->vert_bitmap, vertex); value_i = ~(*face_verts);
value = SET_INT_IN_POINTER(*uniq_verts); (*face_verts)++;
++(*uniq_verts);
} }
*value_p = SET_INT_IN_POINTER(value_i);
BLI_ghash_insert(map, key, value); return value_i;
return GET_INT_FROM_POINTER(value);
} }
else { else {
return GET_INT_FROM_POINTER(*value_p); 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; bvh->totprim = totprim;
if (bvh->nodes) MEM_freeN(bvh->nodes); if (bvh->nodes) MEM_freeN(bvh->nodes);
if (bvh->prim_indices) MEM_freeN(bvh->prim_indices); 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"); "bvh prim indices");
for (int i = 0; i < totprim; ++i) for (int i = 0; i < totprim; ++i)
bvh->prim_indices[i] = i; bvh->prim_indices[i] = i;