diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-04-08 06:51:00 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-04-08 06:58:57 +0400 |
commit | 7867f32fce305382daf28c417bf07d6660bdc64c (patch) | |
tree | 17b0ea1720b6e53ec0bb4f2e740cdfe574a7e3ed | |
parent | 412826a504a95c45b561893aa9cbaebd00d63702 (diff) |
BMesh: minor speedup, avoid calloc+assign, assign all members instead
-rw-r--r-- | source/blender/bmesh/intern/bmesh_core.c | 141 |
1 files changed, 92 insertions, 49 deletions
diff --git a/source/blender/bmesh/intern/bmesh_core.c b/source/blender/bmesh/intern/bmesh_core.c index ed1789ff225..3efee378060 100644 --- a/source/blender/bmesh/intern/bmesh_core.c +++ b/source/blender/bmesh/intern/bmesh_core.c @@ -60,7 +60,11 @@ BMVert *BM_vert_create(BMesh *bm, const float co[3], const BMVert *v_example, const eBMCreateFlag create_flag) { - BMVert *v = BLI_mempool_calloc(bm->vpool); + BMVert *v = BLI_mempool_alloc(bm->vpool); + + + /* --- assign all members --- */ + v->head.data = NULL; #ifdef USE_DEBUG_INDEX_MEMCHECK DEBUG_MEMCHECK_INDEX_INVALIDATE(v) @@ -68,6 +72,26 @@ BMVert *BM_vert_create(BMesh *bm, const float co[3], BM_elem_index_set(v, -1); /* set_ok_invalid */ #endif + v->head.htype = BM_VERT; + v->head.hflag = 0; + v->head.api_flag = 0; + + /* allocate flags */ + v->oflags = bm->vtoolflagpool ? BLI_mempool_calloc(bm->vtoolflagpool) : NULL; + + /* 'v->no' is handled by BM_elem_attrs_copy */ + if (co) { + copy_v3_v3(v->co, co); + } + else { + zero_v3(v->co); + } + zero_v3(v->no); + + v->e = NULL; + /* --- done --- */ + + /* disallow this flag for verts - its meaningless */ BLI_assert((create_flag & BM_CREATE_NO_DOUBLE) == 0); @@ -77,18 +101,6 @@ BMVert *BM_vert_create(BMesh *bm, const float co[3], bm->totvert++; - v->head.htype = BM_VERT; - - /* 'v->no' is handled by BM_elem_attrs_copy */ - if (co) { - copy_v3_v3(v->co, co); - } - - /* allocate flags */ - if (bm->vtoolflagpool) { - v->oflags = BLI_mempool_calloc(bm->vtoolflagpool); - } - if (!(create_flag & BM_CREATE_SKIP_CD)) { if (v_example) { int *keyi; @@ -125,7 +137,11 @@ BMEdge *BM_edge_create(BMesh *bm, BMVert *v1, BMVert *v2, if ((create_flag & BM_CREATE_NO_DOUBLE) && (e = BM_edge_exists(v1, v2))) return e; - e = BLI_mempool_calloc(bm->epool); + e = BLI_mempool_alloc(bm->epool); + + + /* --- assign all members --- */ + e->head.data = NULL; #ifdef USE_DEBUG_INDEX_MEMCHECK DEBUG_MEMCHECK_INDEX_INVALIDATE(e) @@ -133,27 +149,30 @@ BMEdge *BM_edge_create(BMesh *bm, BMVert *v1, BMVert *v2, BM_elem_index_set(e, -1); /* set_ok_invalid */ #endif - /* may add to middle of the pool */ - bm->elem_index_dirty |= BM_EDGE; - bm->elem_table_dirty |= BM_EDGE; - - bm->totedge++; - e->head.htype = BM_EDGE; - + e->head.hflag = BM_ELEM_SMOOTH | BM_ELEM_DRAW; + e->head.api_flag = 0; + /* allocate flags */ - if (bm->etoolflagpool) { - e->oflags = BLI_mempool_calloc(bm->etoolflagpool); - } + e->oflags = bm->etoolflagpool ? BLI_mempool_calloc(bm->etoolflagpool) : NULL; e->v1 = v1; e->v2 = v2; - - BM_elem_flag_enable(e, BM_ELEM_SMOOTH | BM_ELEM_DRAW); - + e->l = NULL; + + memset(&e->v1_disk_link, 0, sizeof(BMDiskLink) * 2); + /* --- done --- */ + + bmesh_disk_edge_append(e, e->v1); bmesh_disk_edge_append(e, e->v2); - + + /* may add to middle of the pool */ + bm->elem_index_dirty |= BM_EDGE; + bm->elem_table_dirty |= BM_EDGE; + + bm->totedge++; + if (!(create_flag & BM_CREATE_SKIP_CD)) { if (e_example) { BM_elem_attrs_copy(bm, bm, e_example, e); @@ -163,7 +182,6 @@ BMEdge *BM_edge_create(BMesh *bm, BMVert *v1, BMVert *v2, } } - BM_CHECK_ELEMENT(e); return e; @@ -174,14 +192,25 @@ static BMLoop *bm_loop_create(BMesh *bm, BMVert *v, BMEdge *e, BMFace *f, { BMLoop *l = NULL; - l = BLI_mempool_calloc(bm->lpool); - l->next = l->prev = NULL; + l = BLI_mempool_alloc(bm->lpool); + + /* --- assign all members --- */ + l->head.data = NULL; + BM_elem_index_set(l, 0); /* set_loop */ + l->head.hflag = 0; + l->head.htype = BM_LOOP; + l->head.api_flag = 0; + l->v = v; l->e = e; l->f = f; - l->radial_next = l->radial_prev = NULL; - l->head.data = NULL; - l->head.htype = BM_LOOP; + + l->radial_next = NULL; + l->radial_prev = NULL; + l->next = NULL; + l->prev = NULL; + /* --- done --- */ + bm->totloop++; @@ -284,36 +313,48 @@ BMFace *BM_face_copy(BMesh *bm_dst, BMesh *bm_src, BMFace *f, /** * only create the face, since this calloc's the length is initialized to 0, * leave adding loops to the caller. + * + * \note, caller needs to handle customdata. */ -BLI_INLINE BMFace *bm_face_create__internal(BMesh *bm, const eBMCreateFlag create_flag) +BLI_INLINE BMFace *bm_face_create__internal(BMesh *bm) { BMFace *f; - f = BLI_mempool_calloc(bm->fpool); + f = BLI_mempool_alloc(bm->fpool); + + /* --- assign all members --- */ + f->head.data = NULL; #ifdef USE_DEBUG_INDEX_MEMCHECK DEBUG_MEMCHECK_INDEX_INVALIDATE(f) #else BM_elem_index_set(f, -1); /* set_ok_invalid */ #endif + f->head.htype = BM_FACE; + f->head.hflag = 0; + f->head.api_flag = 0; + + /* allocate flags */ + f->oflags = bm->ftoolflagpool ? BLI_mempool_calloc(bm->ftoolflagpool) : NULL; + +#ifdef USE_BMESH_HOLES + BLI_listbase_clear(&f->loops); +#else + f->l_first = NULL; +#endif + f->len = 0; + zero_v3(f->no); + f->mat_nr = 0; + /* --- done --- */ + + /* may add to middle of the pool */ bm->elem_index_dirty |= BM_FACE; bm->elem_table_dirty |= BM_FACE; bm->totface++; - f->head.htype = BM_FACE; - - /* allocate flags */ - if (bm->ftoolflagpool) { - f->oflags = BLI_mempool_calloc(bm->ftoolflagpool); - } - - if (!(create_flag & BM_CREATE_SKIP_CD)) { - CustomData_bmesh_set_default(&bm->pdata, &f->head.data); - } - #ifdef USE_BMESH_HOLES f->totbounds = 0; #endif @@ -353,7 +394,7 @@ BMFace *BM_face_create(BMesh *bm, BMVert **verts, BMEdge **edges, const int len, } } - f = bm_face_create__internal(bm, create_flag); + f = bm_face_create__internal(bm); startl = lastl = bm_face_boundary_add(bm, f, verts[0], edges[0], create_flag); @@ -1208,7 +1249,7 @@ static BMFace *bm_face_create__sfme(BMesh *bm, BMFace *UNUSED(example)) BMLoopList *lst; #endif - f = bm_face_create__internal(bm, 0); + f = bm_face_create__internal(bm); #ifdef USE_BMESH_HOLES lst = BLI_mempool_calloc(bm->looplistpool); @@ -1219,6 +1260,8 @@ static BMFace *bm_face_create__sfme(BMesh *bm, BMFace *UNUSED(example)) f->totbounds = 1; #endif + CustomData_bmesh_set_default(&bm->pdata, &f->head.data); + return f; } |