From a8abc11e42fefd8e6192e3a9bcc185b6428d36f4 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 19 Jan 2013 00:17:10 +0000 Subject: dyntopo optimization - fast path for edges with 2 faces using it, was counting the edge-faces then using an iterator, instead use BM_edge_loop_pair() --- source/blender/blenkernel/intern/pbvh_bmesh.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'source/blender/blenkernel/intern/pbvh_bmesh.c') diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c index 7ffadde2f08..7b6ad622deb 100644 --- a/source/blender/blenkernel/intern/pbvh_bmesh.c +++ b/source/blender/blenkernel/intern/pbvh_bmesh.c @@ -439,8 +439,18 @@ static void pbvh_bmesh_face_remove(PBVH *bvh, BMFace *f) static void pbvh_bmesh_edge_loops(BLI_Buffer *buf, BMEdge *e) { - BLI_buffer_resize(buf, BM_edge_face_count(e)); - BM_iter_as_array(NULL, BM_LOOPS_OF_EDGE, e, buf->data, buf->count); + /* fast-path for most common case where an edge has 2 faces, + * no need to iterate twice. + * This assumes that the buffer */ + BMLoop **data = buf->data; + BLI_assert(buf->alloc_count >= 2); + if (LIKELY(BM_edge_loop_pair(e, &data[0], &data[1]))) { + buf->count = 2; + } + else { + BLI_buffer_resize(buf, BM_edge_face_count(e)); + BM_iter_as_array(NULL, BM_LOOPS_OF_EDGE, e, buf->data, buf->count); + } } static void pbvh_bmesh_node_drop_orig(PBVHNode *node) @@ -1003,9 +1013,10 @@ void BKE_pbvh_build_bmesh(PBVH *bvh, BMesh *bm, int smooth_shading, /* Collapse short edges, subdivide long edges */ int BKE_pbvh_bmesh_update_topology(PBVH *bvh, PBVHTopologyUpdateMode mode, - const float center[3], float radius) + const float center[3], float radius) { - BLI_buffer_declare_static(BMFace *, edge_loops, BLI_BUFFER_NOP, 8); + /* 2 is enough for edge faces - manifold edge */ + BLI_buffer_declare_static(BMFace *, edge_loops, BLI_BUFFER_NOP, 2); BLI_buffer_declare_static(BMFace *, deleted_faces, BLI_BUFFER_NOP, 32); int modified = FALSE; -- cgit v1.2.3