diff --git a/source/blender/blenkernel/intern/DerivedMesh.cc b/source/blender/blenkernel/intern/DerivedMesh.cc index 5387eab8844..fbbefab9478 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.cc +++ b/source/blender/blenkernel/intern/DerivedMesh.cc @@ -20,7 +20,6 @@ #include "DNA_object_types.h" #include "DNA_scene_types.h" -#include "BLI_array.h" #include "BLI_bitmap.h" #include "BLI_blenlib.h" #include "BLI_linklist.h" diff --git a/source/blender/blenlib/tests/BLI_stack_test.cc b/source/blender/blenlib/tests/BLI_stack_test.cc index 71699e85c18..47f5d2122df 100644 --- a/source/blender/blenlib/tests/BLI_stack_test.cc +++ b/source/blender/blenlib/tests/BLI_stack_test.cc @@ -5,7 +5,6 @@ #include "testing/testing.h" #include -#include "BLI_array.h" #include "BLI_stack.h" #include "BLI_utildefines.h" diff --git a/source/blender/bmesh/intern/bmesh_core.cc b/source/blender/bmesh/intern/bmesh_core.cc index c78226c4169..eb0656432e2 100644 --- a/source/blender/bmesh/intern/bmesh_core.cc +++ b/source/blender/bmesh/intern/bmesh_core.cc @@ -11,10 +11,10 @@ #include "MEM_guardedalloc.h" #include "BLI_alloca.h" -#include "BLI_array.h" #include "BLI_linklist_stack.h" #include "BLI_math_vector.h" #include "BLI_utildefines_stack.h" +#include "BLI_vector.hh" #include "BLT_translation.h" @@ -26,6 +26,8 @@ #include "bmesh.h" #include "intern/bmesh_private.h" +using blender::Vector; + /* use so valgrinds memcheck alerts us when undefined index is used. * TESTING ONLY! */ // #define USE_DEBUG_INDEX_MEMCHECK @@ -1139,12 +1141,6 @@ BMFace *BM_faces_join(BMesh *bm, BMFace **faces, int totface, const bool do_del) #endif BMLoop *l_iter; BMLoop *l_first; - BMEdge **edges = nullptr; - BMEdge **deledges = nullptr; - BMVert **delverts = nullptr; - BLI_array_staticdeclare(edges, BM_DEFAULT_NGON_STACK_SIZE); - BLI_array_staticdeclare(deledges, BM_DEFAULT_NGON_STACK_SIZE); - BLI_array_staticdeclare(delverts, BM_DEFAULT_NGON_STACK_SIZE); BMVert *v1 = nullptr, *v2 = nullptr; int i; const int cd_loop_mdisp_offset = CustomData_get_offset(&bm->ldata, CD_MDISPS); @@ -1160,6 +1156,10 @@ BMFace *BM_faces_join(BMesh *bm, BMFace **faces, int totface, const bool do_del) bm_elements_systag_enable(faces, totface, _FLAG_JF); + Vector edges; + Vector deledges; + Vector delverts; + for (i = 0; i < totface; i++) { f = faces[i]; l_iter = l_first = BM_FACE_FIRST_LOOP(f); @@ -1171,7 +1171,7 @@ BMFace *BM_faces_join(BMesh *bm, BMFace **faces, int totface, const bool do_del) goto error; } else if (rlen == 1) { - BLI_array_append(edges, l_iter->e); + edges.append(l_iter->e); if (!v1) { v1 = l_iter->v; @@ -1187,7 +1187,7 @@ BMFace *BM_faces_join(BMesh *bm, BMFace **faces, int totface, const bool do_del) * else this will remove the face as well - campbell */ if (!BM_edge_face_count_is_over(l_iter->e, 2)) { if (do_del) { - BLI_array_append(deledges, l_iter->e); + deledges.append(l_iter->e); } BM_ELEM_API_FLAG_ENABLE(l_iter->e, _FLAG_JF); } @@ -1195,14 +1195,14 @@ BMFace *BM_faces_join(BMesh *bm, BMFace **faces, int totface, const bool do_del) else { if (d1 && !BM_ELEM_API_FLAG_TEST(l_iter->e->v1, _FLAG_JF)) { if (do_del) { - BLI_array_append(delverts, l_iter->e->v1); + delverts.append(l_iter->e->v1); } BM_ELEM_API_FLAG_ENABLE(l_iter->e->v1, _FLAG_JF); } if (d2 && !BM_ELEM_API_FLAG_TEST(l_iter->e->v2, _FLAG_JF)) { if (do_del) { - BLI_array_append(delverts, l_iter->e->v2); + delverts.append(l_iter->e->v2); } BM_ELEM_API_FLAG_ENABLE(l_iter->e->v2, _FLAG_JF); } @@ -1223,9 +1223,9 @@ BMFace *BM_faces_join(BMesh *bm, BMFace **faces, int totface, const bool do_del) } /* create region face */ - f_new = BLI_array_len(edges) ? + f_new = !edges.is_empty() ? BM_face_create_ngon( - bm, v1, v2, edges, BLI_array_len(edges), faces[0], BM_CREATE_NOP) : + bm, v1, v2, edges.data(), edges.size(), faces[0], BM_CREATE_NOP) : nullptr; if (UNLIKELY(f_new == nullptr)) { /* Invalid boundary region to join faces */ @@ -1292,12 +1292,12 @@ BMFace *BM_faces_join(BMesh *bm, BMFace **faces, int totface, const bool do_del) /* delete old geometry */ if (do_del) { - for (i = 0; i < BLI_array_len(deledges); i++) { - BM_edge_kill(bm, deledges[i]); + for (BMEdge *edge : deledges) { + BM_edge_kill(bm, edge); } - for (i = 0; i < BLI_array_len(delverts); i++) { - BM_vert_kill(bm, delverts[i]); + for (BMVert *vert : delverts) { + BM_vert_kill(bm, vert); } } else { @@ -1307,18 +1307,11 @@ BMFace *BM_faces_join(BMesh *bm, BMFace **faces, int totface, const bool do_del) } } - BLI_array_free(edges); - BLI_array_free(deledges); - BLI_array_free(delverts); - BM_CHECK_ELEMENT(f_new); return f_new; error: bm_elements_systag_disable(faces, totface, _FLAG_JF); - BLI_array_free(edges); - BLI_array_free(deledges); - BLI_array_free(delverts); return nullptr; } diff --git a/source/blender/bmesh/intern/bmesh_mods.cc b/source/blender/bmesh/intern/bmesh_mods.cc index ecdf6c16457..c986591a903 100644 --- a/source/blender/bmesh/intern/bmesh_mods.cc +++ b/source/blender/bmesh/intern/bmesh_mods.cc @@ -11,14 +11,16 @@ #include "MEM_guardedalloc.h" -#include "BLI_array.h" #include "BLI_math_vector.h" +#include "BLI_vector.hh" #include "BKE_customdata.h" #include "bmesh.h" #include "intern/bmesh_private.h" +using blender::Vector; + bool BM_vert_dissolve(BMesh *bm, BMVert *v) { /* logic for 3 or more is identical */ @@ -361,16 +363,15 @@ BMEdge *BM_vert_collapse_faces(BMesh *bm, if (join_faces) { BMIter fiter; - BMFace **faces = nullptr; BMFace *f; - BLI_array_staticdeclare(faces, BM_DEFAULT_ITER_STACK_SIZE); + Vector faces; BM_ITER_ELEM (f, &fiter, v_kill, BM_FACES_OF_VERT) { - BLI_array_append(faces, f); + faces.append(f); } - if (BLI_array_len(faces) >= 2) { - BMFace *f2 = BM_faces_join(bm, faces, BLI_array_len(faces), true); + if (faces.size() >= 2) { + BMFace *f2 = BM_faces_join(bm, faces.data(), faces.size(), true); if (f2) { BMLoop *l_a, *l_b; @@ -383,10 +384,6 @@ BMEdge *BM_vert_collapse_faces(BMesh *bm, } } } - - BLI_assert(BLI_array_len(faces) < 8); - - BLI_array_free(faces); } else { /* single face or no faces */ @@ -451,8 +448,8 @@ BMVert *BM_edge_split(BMesh *bm, BMEdge *e, BMVert *v, BMEdge **r_e, float fac) { BMVert *v_new, *v_other; BMEdge *e_new; - BMFace **oldfaces = nullptr; - BLI_array_staticdeclare(oldfaces, 32); + + Vector oldfaces; const int cd_loop_mdisp_offset = BM_edge_is_wire(e) ? -1 : CustomData_get_offset(&bm->ldata, CD_MDISPS); @@ -461,17 +458,14 @@ BMVert *BM_edge_split(BMesh *bm, BMEdge *e, BMVert *v, BMEdge **r_e, float fac) /* do we have a multi-res layer? */ if (cd_loop_mdisp_offset != -1) { - BMLoop *l; - int i; - - l = e->l; + BMLoop *l = e->l; do { - BLI_array_append(oldfaces, l->f); + oldfaces.append(l->f); l = l->radial_next; } while (l != e->l); /* flag existing faces so we can differentiate oldfaces from new faces */ - for (i = 0; i < BLI_array_len(oldfaces); i++) { + for (int64_t i = 0; i < oldfaces.size(); i++) { BM_ELEM_API_FLAG_ENABLE(oldfaces[i], _FLAG_OVERLAP); oldfaces[i] = BM_face_copy(bm, bm, oldfaces[i], true, true); BM_ELEM_API_FLAG_DISABLE(oldfaces[i], _FLAG_OVERLAP); @@ -499,19 +493,15 @@ BMVert *BM_edge_split(BMesh *bm, BMEdge *e, BMVert *v, BMEdge **r_e, float fac) BM_data_interp_from_verts(bm, v, v_other, v_new, fac); if (cd_loop_mdisp_offset != -1) { - int i, j; - /* interpolate new/changed loop data from copied old faces */ - for (i = 0; i < BLI_array_len(oldfaces); i++) { + for (BMFace *oldface : oldfaces) { float f_center_old[3]; - BM_face_calc_center_median(oldfaces[i], f_center_old); + BM_face_calc_center_median(oldface, f_center_old); - for (j = 0; j < 2; j++) { + for (int j = 0; j < 2; j++) { BMEdge *e1 = j ? e_new : e; - BMLoop *l; - - l = e1->l; + BMLoop *l = e1->l; if (UNLIKELY(!l)) { BMESH_ASSERT(0); @@ -525,7 +515,7 @@ BMVert *BM_edge_split(BMesh *bm, BMEdge *e, BMVert *v, BMEdge **r_e, float fac) BM_face_calc_center_median(l->f, f_center); BM_face_interp_multires_ex( - bm, l->f, oldfaces[i], f_center, f_center_old, cd_loop_mdisp_offset); + bm, l->f, oldface, f_center, f_center_old, cd_loop_mdisp_offset); } l = l->radial_next; } while (l != e1->l); @@ -533,13 +523,13 @@ BMVert *BM_edge_split(BMesh *bm, BMEdge *e, BMVert *v, BMEdge **r_e, float fac) } /* destroy the old faces */ - for (i = 0; i < BLI_array_len(oldfaces); i++) { - BM_face_verts_kill(bm, oldfaces[i]); + for (BMFace *oldface : oldfaces) { + BM_face_verts_kill(bm, oldface); } /* fix boundaries a bit, doesn't work too well quite yet */ #if 0 - for (j = 0; j < 2; j++) { + for (int j = 0; j < 2; j++) { BMEdge *e1 = j ? e_new : e; BMLoop *l, *l2; @@ -555,8 +545,6 @@ BMVert *BM_edge_split(BMesh *bm, BMEdge *e, BMVert *v, BMEdge **r_e, float fac) } while (l != e1->l); } #endif - - BLI_array_free(oldfaces); } return v_new; @@ -585,55 +573,6 @@ void BM_edge_verts_swap(BMEdge *e) SWAP(BMDiskLink, e->v1_disk_link, e->v2_disk_link); } -#if 0 -/** - * Checks if a face is valid in the data structure - */ -bool BM_face_validate(BMFace *face, FILE *err) -{ - BMIter iter; - BLI_array_declare(verts); - BMVert **verts = nullptr; - BMLoop *l; - int i, j; - bool ret = true; - - if (face->len == 2) { - fprintf(err, "WARNING: found two-edged face. face ptr: %p\n", face); - fflush(err); - } - - BLI_array_grow_items(verts, face->len); - BM_ITER_ELEM_INDEX (l, &iter, face, BM_LOOPS_OF_FACE, i) { - verts[i] = l->v; - if (l->e->v1 == l->e->v2) { - fprintf(err, "Found bmesh edge with identical verts!\n"); - fprintf(err, " edge ptr: %p, vert: %p\n", l->e, l->e->v1); - fflush(err); - ret = false; - } - } - - for (i = 0; i < face->len; i++) { - for (j = 0; j < face->len; j++) { - if (j == i) { - continue; - } - - if (verts[i] == verts[j]) { - fprintf(err, "Found duplicate verts in bmesh face!\n"); - fprintf(err, " face ptr: %p, vert: %p\n", face, verts[i]); - fflush(err); - ret = false; - } - } - } - - BLI_array_free(verts); - return ret; -} -#endif - void BM_edge_calc_rotate(BMEdge *e, const bool ccw, BMLoop **r_l1, BMLoop **r_l2) { BMVert *v1, *v2; diff --git a/source/blender/bmesh/intern/bmesh_mods.h b/source/blender/bmesh/intern/bmesh_mods.h index 3db4a174288..395f4655db7 100644 --- a/source/blender/bmesh/intern/bmesh_mods.h +++ b/source/blender/bmesh/intern/bmesh_mods.h @@ -195,8 +195,6 @@ BMVert *BM_edge_split_n(BMesh *bm, BMEdge *e, int numcuts, BMVert **r_varr); */ void BM_edge_verts_swap(BMEdge *e); -bool BM_face_validate(BMFace *face, FILE *err); - /** * Calculate the 2 loops which _would_ make up the newly rotated Edge * but don't actually change anything. diff --git a/source/blender/bmesh/operators/bmo_dissolve.cc b/source/blender/bmesh/operators/bmo_dissolve.cc index 1be07bb0c27..0dd375bc22e 100644 --- a/source/blender/bmesh/operators/bmo_dissolve.cc +++ b/source/blender/bmesh/operators/bmo_dissolve.cc @@ -10,15 +10,17 @@ #include "MEM_guardedalloc.h" -#include "BLI_array.h" #include "BLI_math_vector.h" #include "BLI_stack.h" +#include "BLI_vector.hh" #include "bmesh.h" #include "bmesh_tools.h" #include "intern/bmesh_operators_private.h" +using blender::Vector; + /* ***_ISGC: mark for garbage-collection */ #define FACE_MARK 1 @@ -119,17 +121,8 @@ void bmo_dissolve_faces_exec(BMesh *bm, BMOperator *op) { BMOIter oiter; BMFace *f; - /* List of face arrays, the first element in each array in the length. */ - struct { - BMFace **faces; - int faces_len; - } *regions = nullptr, *region; - BMFace **faces = nullptr; - BLI_array_declare(regions); - BLI_array_declare(faces); BMFace *act_face = bm->act_face; BMWalker regwalker; - int i; const bool use_verts = BMO_slot_bool_get(op->slots_in, "use_verts"); @@ -146,9 +139,11 @@ void bmo_dissolve_faces_exec(BMesh *bm, BMOperator *op) BMO_slot_buffer_flag_enable(bm, op->slots_in, "faces", BM_FACE, FACE_MARK | FACE_TAG); + /* List of regions which are themselves a list of faces. */ + Vector> regions; + /* collect region */ BMO_ITER (f, &oiter, op->slots_in, "faces", BM_FACE) { - BMFace *f_iter; if (!BMO_face_flag_test(bm, f, FACE_TAG)) { continue; } @@ -168,29 +163,21 @@ void bmo_dissolve_faces_exec(BMesh *bm, BMOperator *op) if ((faces_init[0] = static_cast(BMW_begin(®walker, f))) && (faces_init[1] = static_cast(BMW_step(®walker)))) { + Vector faces; + faces.append(faces_init[0]); + faces.append(faces_init[1]); - BLI_assert(BLI_array_len(faces) == 0); - - BLI_array_append(faces, faces_init[0]); - BLI_array_append(faces, faces_init[1]); - + BMFace *f_iter; while ((f_iter = static_cast(BMW_step(®walker)))) { - BLI_array_append(faces, f_iter); + faces.append(f_iter); } - for (i = 0; i < BLI_array_len(faces); i++) { - f_iter = faces[i]; - BMO_face_flag_disable(bm, f_iter, FACE_TAG); - BMO_face_flag_enable(bm, f_iter, FACE_ORIG); + for (BMFace *face : faces) { + BMO_face_flag_disable(bm, face, FACE_TAG); + BMO_face_flag_enable(bm, face, FACE_ORIG); } - region = BLI_array_append_ret(regions); - region->faces = faces; - region->faces_len = BLI_array_len(faces); - - BLI_array_clear(faces); - /* Forces a new allocation. */ - faces = nullptr; + regions.append_as(std::move(faces)); } BMW_end(®walker); @@ -199,13 +186,10 @@ void bmo_dissolve_faces_exec(BMesh *bm, BMOperator *op) /* track how many faces we should end up with */ int totface_target = bm->totface; - for (i = 0; i < BLI_array_len(regions); i++) { - region = ®ions[i]; + for (Vector &faces : regions) { + const int64_t faces_len = faces.size(); - const int faces_len = region->faces_len; - faces = region->faces; - - BMFace *f_new = BM_faces_join(bm, faces, faces_len, true); + BMFace *f_new = BM_faces_join(bm, faces.data(), faces_len, true); if (f_new != nullptr) { /* Maintain the active face. */ if (act_face && bm->act_face == nullptr) { @@ -226,8 +210,8 @@ void bmo_dissolve_faces_exec(BMesh *bm, BMOperator *op) * This could optionally do a partial merge, where some faces are joined. */ /* Prevent these faces from being removed. */ - for (int j = 0; j < faces_len; j++) { - BMO_face_flag_disable(bm, faces[j], FACE_ORIG); + for (BMFace *face : faces) { + BMO_face_flag_disable(bm, face, FACE_ORIG); } } } @@ -253,13 +237,6 @@ void bmo_dissolve_faces_exec(BMesh *bm, BMOperator *op) BLI_assert(!BMO_error_occurred_at_level(bm, BMO_ERROR_FATAL)); BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "region.out", BM_FACE, FACE_NEW); - - /* free/cleanup */ - for (i = 0; i < BLI_array_len(regions); i++) { - MEM_freeN(regions[i].faces); - } - - BLI_array_free(regions); } void bmo_dissolve_edges_exec(BMesh *bm, BMOperator *op) diff --git a/source/blender/bmesh/operators/bmo_edgenet.cc b/source/blender/bmesh/operators/bmo_edgenet.cc index db32e0ed59e..85fcb3ce836 100644 --- a/source/blender/bmesh/operators/bmo_edgenet.cc +++ b/source/blender/bmesh/operators/bmo_edgenet.cc @@ -10,14 +10,16 @@ #include "MEM_guardedalloc.h" -#include "BLI_array.h" #include "BLI_math_vector.h" +#include "BLI_vector.hh" #include "bmesh.h" #include "bmesh_tools.h" #include "intern/bmesh_operators_private.h" /* own include */ +using blender::Vector; + #define EDGE_MARK 1 #define EDGE_VIS 2 @@ -96,10 +98,6 @@ void bmo_edgenet_prepare_exec(BMesh *bm, BMOperator *op) { BMOIter siter; BMEdge *e; - BMEdge **edges1 = nullptr, **edges2 = nullptr, **edges; - BLI_array_declare(edges1); - BLI_array_declare(edges2); - BLI_array_declare(edges); bool ok = true; int i, count; @@ -126,6 +124,10 @@ void bmo_edgenet_prepare_exec(BMesh *bm, BMOperator *op) return; } + Vector edges1; + Vector edges2; + Vector *edges; + /* find connected loops within the input edge */ count = 0; while (true) { @@ -144,10 +146,10 @@ void bmo_edgenet_prepare_exec(BMesh *bm, BMOperator *op) } if (!count) { - edges = edges1; + edges = &edges1; } else if (count == 1) { - edges = edges2; + edges = &edges2; } else { break; @@ -156,69 +158,54 @@ void bmo_edgenet_prepare_exec(BMesh *bm, BMOperator *op) i = 0; while (e) { BMO_edge_flag_enable(bm, e, EDGE_VIS); - BLI_array_grow_one(edges); - edges[i] = e; + edges->append(e); e = edge_next(bm, e); i++; } - if (!count) { - edges1 = edges; - BLI_array_len_set(edges1, BLI_array_len(edges)); - } - else { - edges2 = edges; - BLI_array_len_set(edges2, BLI_array_len(edges)); - } - - BLI_array_clear(edges); count++; } - if (edges1 && BLI_array_len(edges1) > 2 && - BM_edge_share_vert_check(edges1[0], edges1[BLI_array_len(edges1) - 1])) + if (edges1.size() > 2 && BM_edge_share_vert_check(edges1.first(), edges1.last())) { - if (edges2 && BLI_array_len(edges2) > 2 && - BM_edge_share_vert_check(edges2[0], edges2[BLI_array_len(edges2) - 1])) + if (edges2.size() > 2 && + BM_edge_share_vert_check(edges2.first(), edges2.last())) { - BLI_array_free(edges1); - BLI_array_free(edges2); return; } edges1 = edges2; - edges2 = nullptr; + edges2.clear(); } - if (edges2 && BLI_array_len(edges2) > 2 && - BM_edge_share_vert_check(edges2[0], edges2[BLI_array_len(edges2) - 1])) + if (edges2.size() > 2 && BM_edge_share_vert_check(edges2.first(), edges2.last())) { - edges2 = nullptr; + edges2.clear(); } /* two unconnected loops, connect the */ - if (edges1 && edges2) { + if (!edges1.is_empty() && !edges2.is_empty()) { BMVert *v1, *v2, *v3, *v4; float dvec1[3]; float dvec2[3]; - if (BLI_array_len(edges1) == 1) { + if (edges1.size() == 1) { v1 = edges1[0]->v1; v2 = edges1[0]->v2; } else { v1 = BM_vert_in_edge(edges1[1], edges1[0]->v1) ? edges1[0]->v2 : edges1[0]->v1; - i = BLI_array_len(edges1) - 1; + i = edges1.size() - 1; v2 = BM_vert_in_edge(edges1[i - 1], edges1[i]->v1) ? edges1[i]->v2 : edges1[i]->v1; } - if (BLI_array_len(edges2) == 1) { + if (edges2.size() == 1) { v3 = edges2[0]->v1; v4 = edges2[0]->v2; } else { v3 = BM_vert_in_edge(edges2[1], edges2[0]->v1) ? edges2[0]->v2 : edges2[0]->v1; - i = BLI_array_len(edges2) - 1; + i = edges2.size() - 1; v4 = BM_vert_in_edge(edges2[i - 1], edges2[i]->v1) ? edges2[i]->v2 : edges2[i]->v1; } @@ -246,12 +233,12 @@ void bmo_edgenet_prepare_exec(BMesh *bm, BMOperator *op) e = BM_edge_create(bm, v2, v4, nullptr, BM_CREATE_NO_DOUBLE); BMO_edge_flag_enable(bm, e, ELE_NEW); } - else if (edges1) { + else if (!edges1.is_empty()) { BMVert *v1, *v2; - if (BLI_array_len(edges1) > 1) { + if (edges1.size() > 1) { v1 = BM_vert_in_edge(edges1[1], edges1[0]->v1) ? edges1[0]->v2 : edges1[0]->v1; - i = BLI_array_len(edges1) - 1; + i = edges1.size() - 1; v2 = BM_vert_in_edge(edges1[i - 1], edges1[i]->v1) ? edges1[i]->v2 : edges1[i]->v1; e = BM_edge_create(bm, v1, v2, nullptr, BM_CREATE_NO_DOUBLE); BMO_edge_flag_enable(bm, e, ELE_NEW); @@ -259,7 +246,4 @@ void bmo_edgenet_prepare_exec(BMesh *bm, BMOperator *op) } BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "edges.out", BM_EDGE, ELE_NEW); - - BLI_array_free(edges1); - BLI_array_free(edges2); } diff --git a/source/blender/bmesh/operators/bmo_hull.cc b/source/blender/bmesh/operators/bmo_hull.cc index a534e9a2693..b9ba01651e8 100644 --- a/source/blender/bmesh/operators/bmo_hull.cc +++ b/source/blender/bmesh/operators/bmo_hull.cc @@ -12,9 +12,9 @@ # include "MEM_guardedalloc.h" -# include "BLI_array.h" # include "BLI_listbase.h" # include "BLI_math_geom.h" +# include "BLI_vector.hh" # include "RBI_hull_api.h" @@ -25,6 +25,8 @@ # include "intern/bmesh_operators_private.h" /* own include */ +using blender::Vector; + /* Internal operator flags */ enum { HULL_FLAG_INPUT = (1 << 0), @@ -464,9 +466,6 @@ static BMVert **hull_verts_from_bullet(plConvexHull hull, static void hull_from_bullet(BMesh *bm, BMOperator *op, BLI_mempool *hull_triangles) { - int *fvi = nullptr; - BLI_array_declare(fvi); - BMVert **input_verts; float(*coords)[3]; BMVert **hull_verts; @@ -483,6 +482,7 @@ static void hull_from_bullet(BMesh *bm, BMOperator *op, BLI_mempool *hull_triang hull_verts = hull_verts_from_bullet(hull, input_verts, num_input_verts); count = plConvexHullNumFaces(hull); + Vector fvi; for (i = 0; i < count; i++) { const int len = plConvexHullGetFaceSize(hull, i); @@ -491,9 +491,8 @@ static void hull_from_bullet(BMesh *bm, BMOperator *op, BLI_mempool *hull_triang int j; /* Get face vertex indices */ - BLI_array_clear(fvi); - BLI_array_grow_items(fvi, len); - plConvexHullGetFaceVertices(hull, i, fvi); + fvi.reinitialize(len); + plConvexHullGetFaceVertices(hull, i, fvi.data()); /* NOTE: here we throw away any NGons from Bullet and turn * them into triangle fans. Would be nice to use these @@ -509,8 +508,6 @@ static void hull_from_bullet(BMesh *bm, BMOperator *op, BLI_mempool *hull_triang } } - BLI_array_free(fvi); - plConvexHullDelete(hull); MEM_freeN(hull_verts); diff --git a/source/blender/bmesh/operators/bmo_subdivide.cc b/source/blender/bmesh/operators/bmo_subdivide.cc index a8c1c5bc11a..60639acdf65 100644 --- a/source/blender/bmesh/operators/bmo_subdivide.cc +++ b/source/blender/bmesh/operators/bmo_subdivide.cc @@ -8,14 +8,16 @@ * Edge based subdivision with various subdivision patterns. */ +#include + #include "MEM_guardedalloc.h" -#include "BLI_array.h" #include "BLI_math_geom.h" #include "BLI_math_vector.h" #include "BLI_noise.h" #include "BLI_rand.h" #include "BLI_stack.h" +#include "BLI_vector.hh" #include "BKE_customdata.h" @@ -23,6 +25,8 @@ #include "intern/bmesh_operators_private.h" #include "intern/bmesh_private.h" +using blender::Vector; + struct SubDParams { int numcuts; float smooth; @@ -911,17 +915,10 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) SubDParams params; BLI_Stack *facedata; BMIter viter, fiter, liter; - BMVert *v, **verts = nullptr; + BMVert *v; BMEdge *edge; - BMEdge **edges = nullptr; - BLI_array_declare(edges); - BMLoop *(*loops_split)[2] = nullptr; - BLI_array_declare(loops_split); - BMLoop **loops = nullptr; - BLI_array_declare(loops); BMLoop *l_new, *l; BMFace *face; - BLI_array_declare(verts); float smooth, fractal, along_normal; bool use_sphere, use_single_edge, use_grid_fill, use_only_quads; int cornertype, seed, i, j, a, b, numcuts, totesel, smooth_falloff; @@ -1017,6 +1014,9 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) facedata = BLI_stack_new(sizeof(SubDFaceData), __func__); + Vector verts; + Vector edges; + BM_ITER_MESH (face, &fiter, bm, BM_FACES_OF_MESH) { BMEdge *e1 = nullptr, *e2 = nullptr; float vec1[3], vec2[3]; @@ -1028,12 +1028,8 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) } /* figure out which pattern to use */ - - BLI_array_clear(edges); - BLI_array_clear(verts); - - BLI_array_grow_items(edges, face->len); - BLI_array_grow_items(verts, face->len); + verts.reinitialize(face->len); + edges.reinitialize(face->len); totesel = 0; BM_ITER_ELEM_INDEX (l_new, &liter, face, BM_LOOPS_OF_FACE, i) { @@ -1157,30 +1153,27 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) copy_v3_v3(v->co, co); } + using LoopPair = std::array; + Vector loops; + Vector loops_split; for (; !BLI_stack_is_empty(facedata); BLI_stack_discard(facedata)) { SubDFaceData *fd = static_cast(BLI_stack_peek(facedata)); face = fd->face; /* figure out which pattern to use */ - BLI_array_clear(verts); - pat = fd->pat; if (!pat && fd->totedgesel == 2) { - int vlen; - /* ok, no pattern. we still may be able to do something */ - BLI_array_clear(loops); - BLI_array_clear(loops_split); /* for case of two edges, connecting them shouldn't be too hard */ - BLI_array_grow_items(loops, face->len); + loops.reinitialize(face->len); BM_ITER_ELEM_INDEX (l, &liter, face, BM_LOOPS_OF_FACE, a) { loops[a] = l; } - vlen = BLI_array_len(loops); + const int64_t vlen = loops.size(); /* find the boundary of one of the split edges */ for (a = 0; a < vlen; a++) { @@ -1210,7 +1203,7 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) b += numcuts - 1; - BLI_array_grow_items(loops_split, numcuts); + loops_split.reinitialize(numcuts); for (j = 0; j < numcuts; j++) { bool ok = true; @@ -1262,12 +1255,11 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) */ // BM_face_splits_check_legal(bm, face, loops_split, BLI_array_len(loops_split)); - for (j = 0; j < BLI_array_len(loops_split); j++) { - if (loops_split[j][0]) { + for (const LoopPair &loop_split : loops_split) { + if (loop_split[0]) { BMFace *f_new; - BLI_assert(BM_edge_exists(loops_split[j][0]->v, loops_split[j][1]->v) == nullptr); - f_new = BM_face_split( - bm, face, loops_split[j][0], loops_split[j][1], &l_new, nullptr, false); + BLI_assert(BM_edge_exists(loop_split[0]->v, loop_split[1]->v) == nullptr); + f_new = BM_face_split(bm, face, loop_split[0], loop_split[1], &l_new, nullptr, false); if (f_new) { BMO_edge_flag_enable(bm, l_new->e, ELE_INNER); } @@ -1288,15 +1280,14 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) } } - BLI_array_grow_items(verts, face->len); - + verts.reinitialize(face->len); BM_ITER_ELEM_INDEX (l_new, &liter, face, BM_LOOPS_OF_FACE, j) { b = (j - a + face->len) % face->len; verts[b] = l_new->v; } BM_CHECK_ELEMENT(face); - pat->connectexec(bm, face, verts, ¶ms); + pat->connectexec(bm, face, verts.data(), ¶ms); } /* copy original-geometry displacements to current coordinates */ @@ -1309,14 +1300,6 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) BM_data_layer_free_n(bm, &bm->vdata, CD_SHAPEKEY, params.shape_info.tmpkey); BLI_stack_free(facedata); - if (edges) { - BLI_array_free(edges); - } - if (verts) { - BLI_array_free(verts); - } - BLI_array_free(loops_split); - BLI_array_free(loops); BMO_slot_buffer_from_enabled_flag( bm, op, op->slots_out, "geom_inner.out", BM_ALL_NOLOOP, ELE_INNER); diff --git a/source/blender/bmesh/tools/bmesh_bevel.cc b/source/blender/bmesh/tools/bmesh_bevel.cc index 9cd864cb295..3e4ec78f1fa 100644 --- a/source/blender/bmesh/tools/bmesh_bevel.cc +++ b/source/blender/bmesh/tools/bmesh_bevel.cc @@ -16,13 +16,13 @@ #include "DNA_scene_types.h" #include "BLI_alloca.h" -#include "BLI_array.h" #include "BLI_math_geom.h" #include "BLI_math_matrix.h" #include "BLI_math_rotation.h" #include "BLI_math_vector.h" #include "BLI_memarena.h" #include "BLI_utildefines.h" +#include "BLI_vector.hh" #include "BKE_curveprofile.h" #include "BKE_customdata.h" @@ -36,6 +36,8 @@ #include "./intern/bmesh_private.h" +using blender::Vector; + // #define BEVEL_DEBUG_TIME #ifdef BEVEL_DEBUG_TIME # include "PIL_time.h" @@ -4924,12 +4926,9 @@ static BMFace *frep_for_center_poly(BevelParams *bp, BevVert *bv) static void build_center_ngon(BevelParams *bp, BMesh *bm, BevVert *bv, int mat_nr) { VMesh *vm = bv->vmesh; - BMVert **vv = nullptr; - BMFace **vf = nullptr; - BMEdge **ve = nullptr; - BLI_array_staticdeclare(vv, BM_DEFAULT_NGON_STACK_SIZE); - BLI_array_staticdeclare(vf, BM_DEFAULT_NGON_STACK_SIZE); - BLI_array_staticdeclare(ve, BM_DEFAULT_NGON_STACK_SIZE); + Vector vv; + Vector vf; + Vector ve; int ns2 = vm->seg / 2; BMFace *frep; @@ -4947,28 +4946,24 @@ static void build_center_ngon(BevelParams *bp, BMesh *bm, BevVert *bv, int mat_n BoundVert *v = vm->boundstart; do { int i = v->index; - BLI_array_append(vv, mesh_vert(vm, i, ns2, ns2)->v); + vv.append(mesh_vert(vm, i, ns2, ns2)->v); if (frep) { - BLI_array_append(vf, frep); + vf.append(frep); if (ELEM(v, frep_unsnapped[0], frep_unsnapped[1], frep_unsnapped[2])) { - BLI_array_append(ve, nullptr); + ve.append(nullptr); } else { BMEdge *frep_e = find_closer_edge(mesh_vert(vm, i, ns2, ns2)->v->co, frep_e1, frep_e2); - BLI_array_append(ve, frep_e); + ve.append(frep_e); } } else { - BLI_array_append(vf, boundvert_rep_face(v, nullptr)); - BLI_array_append(ve, nullptr); + vf.append(boundvert_rep_face(v, nullptr)); + ve.append(nullptr); } } while ((v = v->next) != vm->boundstart); - BMFace *f = bev_create_ngon(bm, vv, BLI_array_len(vv), vf, frep, ve, mat_nr, true); + BMFace *f = bev_create_ngon(bm, vv.data(), vv.size(), vf.data(), frep, ve.data(), mat_nr, true); record_face_kind(bp, f, F_VERT); - - BLI_array_free(vv); - BLI_array_free(vf); - BLI_array_free(ve); } /** @@ -5698,10 +5693,8 @@ static void bevel_build_cutoff(BevelParams *bp, BMesh *bm, BevVert *bv) bndv = bv->vmesh->boundstart; do { int i = bndv->index; - BMEdge **bmedges = nullptr; - BMFace **bmfaces = nullptr; - BLI_array_staticdeclare(bmedges, BM_DEFAULT_NGON_STACK_SIZE); - BLI_array_staticdeclare(bmfaces, BM_DEFAULT_NGON_STACK_SIZE); + Vector bmedges; + Vector bmfaces; /* Add the first corner vertex under this boundvert. */ face_bmverts[0] = mesh_vert(bv->vmesh, i, 1, 0)->v; @@ -5735,22 +5728,17 @@ static void bevel_build_cutoff(BevelParams *bp, BMesh *bm, BevVert *bv) bev_create_ngon(bm, face_bmverts, bp->seg + 2 + build_center_face, - bmfaces, + bmfaces.data(), nullptr, - bmedges, + bmedges.data(), bp->mat_nr, true); - - BLI_array_free(bmedges); - BLI_array_free(bmfaces); } while ((bndv = bndv->next) != bv->vmesh->boundstart); /* Create the bottom face if it should be built, reusing previous face_bmverts allocation. */ if (build_center_face) { - BMEdge **bmedges = nullptr; - BMFace **bmfaces = nullptr; - BLI_array_staticdeclare(bmedges, BM_DEFAULT_NGON_STACK_SIZE); - BLI_array_staticdeclare(bmfaces, BM_DEFAULT_NGON_STACK_SIZE); + Vector bmedges; + Vector bmfaces; /* Add all of the corner vertices to this face. */ for (int i = 0; i < n_bndv; i++) { @@ -5758,22 +5746,17 @@ static void bevel_build_cutoff(BevelParams *bp, BMesh *bm, BevVert *bv) face_bmverts[i] = mesh_vert(bv->vmesh, i, 1, 0)->v; } // BLI_array_append(bmfaces, repface); - bev_create_ngon(bm, face_bmverts, n_bndv, bmfaces, nullptr, bmedges, bp->mat_nr, true); - - BLI_array_free(bmedges); - BLI_array_free(bmfaces); + bev_create_ngon( + bm, face_bmverts, n_bndv, bmfaces.data(), nullptr, bmedges.data(), bp->mat_nr, true); } } static BMFace *bevel_build_poly(BevelParams *bp, BMesh *bm, BevVert *bv) { VMesh *vm = bv->vmesh; - BMVert **bmverts = nullptr; - BMEdge **bmedges = nullptr; - BMFace **bmfaces = nullptr; - BLI_array_staticdeclare(bmverts, BM_DEFAULT_NGON_STACK_SIZE); - BLI_array_staticdeclare(bmedges, BM_DEFAULT_NGON_STACK_SIZE); - BLI_array_staticdeclare(bmfaces, BM_DEFAULT_NGON_STACK_SIZE); + Vector bmverts; + Vector bmedges; + Vector bmfaces; BMFace *repface; BMEdge *repface_e1, *repface_e2; @@ -5792,34 +5775,34 @@ static BMFace *bevel_build_poly(BevelParams *bp, BMesh *bm, BevVert *bv) do { /* Accumulate vertices for vertex ngon. */ /* Also accumulate faces in which uv interpolation is to happen for each. */ - BLI_array_append(bmverts, bndv->nv.v); + bmverts.append(bndv->nv.v); if (repface) { - BLI_array_append(bmfaces, repface); + bmfaces.append(repface); if (ELEM(bndv, unsnapped[0], unsnapped[1], unsnapped[2])) { - BLI_array_append(bmedges, nullptr); + bmedges.append(nullptr); } else { BMEdge *frep_e = find_closer_edge(bndv->nv.v->co, repface_e1, repface_e2); - BLI_array_append(bmedges, frep_e); + bmedges.append(frep_e); } } else { - BLI_array_append(bmfaces, boundvert_rep_face(bndv, nullptr)); - BLI_array_append(bmedges, nullptr); + bmfaces.append(boundvert_rep_face(bndv, nullptr)); + bmedges.append(nullptr); } n++; if (bndv->ebev && bndv->ebev->seg > 1) { for (int k = 1; k < bndv->ebev->seg; k++) { - BLI_array_append(bmverts, mesh_vert(vm, bndv->index, 0, k)->v); + bmverts.append(mesh_vert(vm, bndv->index, 0, k)->v); if (repface) { - BLI_array_append(bmfaces, repface); + bmfaces.append(repface); BMEdge *frep_e = find_closer_edge( mesh_vert(vm, bndv->index, 0, k)->v->co, repface_e1, repface_e2); - BLI_array_append(bmedges, k < bndv->ebev->seg / 2 ? nullptr : frep_e); + bmedges.append(k < bndv->ebev->seg / 2 ? nullptr : frep_e); } else { - BLI_array_append(bmfaces, boundvert_rep_face(bndv, nullptr)); - BLI_array_append(bmedges, nullptr); + bmfaces.append(boundvert_rep_face(bndv, nullptr)); + bmedges.append(nullptr); } n++; } @@ -5828,15 +5811,13 @@ static BMFace *bevel_build_poly(BevelParams *bp, BMesh *bm, BevVert *bv) BMFace *f; if (n > 2) { - f = bev_create_ngon(bm, bmverts, n, bmfaces, repface, bmedges, bp->mat_nr, true); + f = bev_create_ngon( + bm, bmverts.data(), n, bmfaces.data(), repface, bmedges.data(), bp->mat_nr, true); record_face_kind(bp, f, F_VERT); } else { f = nullptr; } - BLI_array_free(bmverts); - BLI_array_free(bmedges); - BLI_array_free(bmfaces); return f; } @@ -6108,10 +6089,8 @@ static float edge_face_angle(EdgeHalf *e) */ static int bevel_edge_order_extend(BMesh *bm, BevVert *bv, int i) { - BMEdge **sucs = nullptr; - BMEdge **save_path = nullptr; - BLI_array_staticdeclare(sucs, 4); /* Likely very few faces attached to same edge. */ - BLI_array_staticdeclare(save_path, BM_DEFAULT_NGON_STACK_SIZE); + Vector sucs; /* Likely very few faces attached to same edge. */ + Vector save_path; /* Fill sucs with all unmarked edges of bmesh. */ BMEdge *bme = bv->edges[i].e; @@ -6120,10 +6099,10 @@ static int bevel_edge_order_extend(BMesh *bm, BevVert *bv, int i) BM_ITER_ELEM (l, &iter, bme, BM_LOOPS_OF_EDGE) { BMEdge *bme2 = (l->v == bv->v) ? l->prev->e : l->next->e; if (!BM_BEVEL_EDGE_TAG_TEST(bme2)) { - BLI_array_append(sucs, bme2); + sucs.append(bme2); } } - int nsucs = BLI_array_len(sucs); + const int64_t nsucs = sucs.size(); int bestj = i; int j = i; @@ -6139,9 +6118,9 @@ static int bevel_edge_order_extend(BMesh *bm, BevVert *bv, int i) (tryj == bestj && edges_face_connected_at_vert(bv->edges[tryj].e, bv->edges[0].e))) { bestj = tryj; - BLI_array_clear(save_path); + save_path.clear(); for (int k = j + 1; k <= bestj; k++) { - BLI_array_append(save_path, bv->edges[k].e); + save_path.append(bv->edges[k].e); } } /* Now reset to path only-going-to-j state. */ @@ -6160,8 +6139,6 @@ static int bevel_edge_order_extend(BMesh *bm, BevVert *bv, int i) BM_BEVEL_EDGE_TAG_ENABLE(bv->edges[k].e); } } - BLI_array_free(sucs); - BLI_array_free(save_path); return bestj; } @@ -6621,12 +6598,9 @@ static BevVert *bevel_vert_construct(BMesh *bm, BevelParams *bp, BMVert *v) static bool bev_rebuild_polygon(BMesh *bm, BevelParams *bp, BMFace *f) { bool do_rebuild = false; - BMVert **vv = nullptr; - BMVert **vv_fix = nullptr; - BMEdge **ee = nullptr; - BLI_array_staticdeclare(vv, BM_DEFAULT_NGON_STACK_SIZE); - BLI_array_staticdeclare(vv_fix, BM_DEFAULT_NGON_STACK_SIZE); - BLI_array_staticdeclare(ee, BM_DEFAULT_NGON_STACK_SIZE); + Vector vv; + Vector vv_fix; + Vector ee; BMIter liter; BMLoop *l; @@ -6689,8 +6663,8 @@ static bool bev_rebuild_polygon(BMesh *bm, BevelParams *bp, BMFace *f) BLI_assert(vstart != nullptr && vend != nullptr); BoundVert *v = vstart; if (!on_profile_start) { - BLI_array_append(vv, v->nv.v); - BLI_array_append(ee, bme); + vv.append(v->nv.v); + ee.append(bme); } while (v != vend) { /* Check for special case: multi-segment 3rd face opposite a beveled edge with no vmesh. */ @@ -6714,10 +6688,10 @@ static bool bev_rebuild_polygon(BMesh *bm, BevelParams *bp, BMFace *f) for (int k = kstart; k <= kend; k++) { BMVert *bmv = mesh_vert(vm, i, 0, k)->v; if (bmv) { - BLI_array_append(vv, bmv); - BLI_array_append(ee, bme); /* TODO: Maybe better edge here. */ + vv.append(bmv); + ee.append(bme); /* TODO: Maybe better edge here. */ if (corner3special && v->ebev && !bv->any_seam && k != vm->seg) { - BLI_array_append(vv_fix, bmv); + vv_fix.append(bmv); } } } @@ -6743,10 +6717,10 @@ static bool bev_rebuild_polygon(BMesh *bm, BevelParams *bp, BMFace *f) for (int k = kstart; k >= kend; k--) { BMVert *bmv = mesh_vert(vm, i, 0, k)->v; if (bmv) { - BLI_array_append(vv, bmv); - BLI_array_append(ee, bme); + vv.append(bmv); + ee.append(bme); if (corner3special && v->ebev && !bv->any_seam && k != 0) { - BLI_array_append(vv_fix, bmv); + vv_fix.append(bmv); } } } @@ -6756,20 +6730,20 @@ static bool bev_rebuild_polygon(BMesh *bm, BevelParams *bp, BMFace *f) do_rebuild = true; } else { - BLI_array_append(vv, l->v); - BLI_array_append(ee, l->e); + vv.append(l->v); + ee.append(l->e); } } if (do_rebuild) { - int n = BLI_array_len(vv); - BMFace *f_new = bev_create_ngon(bm, vv, n, nullptr, f, nullptr, -1, true); + const int64_t n = vv.size(); + BMFace *f_new = bev_create_ngon(bm, vv.data(), n, nullptr, f, nullptr, -1, true); - for (int k = 0; k < BLI_array_len(vv_fix); k++) { + for (int64_t k = 0; k < vv_fix.size(); k++) { bev_merge_uvs(bm, vv_fix[k]); } /* Copy attributes from old edges. */ - BLI_assert(n == BLI_array_len(ee)); + BLI_assert(n == ee.size()); BMEdge *bme_prev = ee[n - 1]; for (int k = 0; k < n; k++) { BMEdge *bme_new = BM_edge_exists(vv[k], vv[(k + 1) % n]); @@ -6819,9 +6793,6 @@ static bool bev_rebuild_polygon(BMesh *bm, BevelParams *bp, BMFace *f) } } - BLI_array_free(vv); - BLI_array_free(vv_fix); - BLI_array_free(ee); return do_rebuild; } diff --git a/source/blender/compositor/intern/COM_MultiThreadedRowOperation.h b/source/blender/compositor/intern/COM_MultiThreadedRowOperation.h index 48e376444ab..c88d231fa80 100644 --- a/source/blender/compositor/intern/COM_MultiThreadedRowOperation.h +++ b/source/blender/compositor/intern/COM_MultiThreadedRowOperation.h @@ -4,8 +4,6 @@ #pragma once -#include "BLI_array.h" - #include "COM_MultiThreadedOperation.h" namespace blender::compositor { diff --git a/source/blender/editors/interface/view2d.cc b/source/blender/editors/interface/view2d.cc index 4e161c1d1be..8fc5b52c5a5 100644 --- a/source/blender/editors/interface/view2d.cc +++ b/source/blender/editors/interface/view2d.cc @@ -16,7 +16,6 @@ #include "DNA_scene_types.h" #include "DNA_userdef_types.h" -#include "BLI_array.h" #include "BLI_easing.h" #include "BLI_link_utils.h" #include "BLI_listbase.h" diff --git a/source/blender/editors/mesh/editmesh_rip.cc b/source/blender/editors/mesh/editmesh_rip.cc index 7097eda25cb..40801eb1795 100644 --- a/source/blender/editors/mesh/editmesh_rip.cc +++ b/source/blender/editors/mesh/editmesh_rip.cc @@ -10,9 +10,10 @@ #include "DNA_object_types.h" -#include "BLI_array.h" #include "BLI_math_geom.h" #include "BLI_math_vector.h" +#include "BLI_span.hh" +#include "BLI_vector.hh" #include "BKE_context.h" #include "BKE_editmesh.h" @@ -36,6 +37,9 @@ #include "mesh_intern.h" /* own include */ +using blender::Span; +using blender::Vector; + /* -------------------------------------------------------------------- */ /** \name Local Utilities * \{ */ @@ -221,7 +225,7 @@ struct EdgeLoopPair { BMLoop *l_b; }; -static EdgeLoopPair *edbm_ripsel_looptag_helper(BMesh *bm) +static Vector edbm_ripsel_looptag_helper(BMesh *bm) { BMIter fiter; BMIter liter; @@ -233,10 +237,6 @@ static EdgeLoopPair *edbm_ripsel_looptag_helper(BMesh *bm) int uid_end; int uid = bm->totedge; /* can start anywhere */ - EdgeLoopPair *eloop_pairs = nullptr; - BLI_array_declare(eloop_pairs); - EdgeLoopPair *lp; - /* initialize loops with dummy invalid index values */ BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) { BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { @@ -245,6 +245,8 @@ static EdgeLoopPair *edbm_ripsel_looptag_helper(BMesh *bm) } bm->elem_index_dirty |= BM_LOOP; + Vector eloop_pairs; + /* set contiguous loops ordered 'uid' values for walking after split */ while (true) { int tot = 0; @@ -299,9 +301,10 @@ static EdgeLoopPair *edbm_ripsel_looptag_helper(BMesh *bm) uid_start = uid; uid = uid_end + bm->totedge; - lp = BLI_array_append_ret(eloop_pairs); /* no need to check, we know this will be true */ - BM_edge_loop_pair(e_last, &lp->l_a, &lp->l_b); + EdgeLoopPair lp; + BM_edge_loop_pair(e_last, &lp.l_a, &lp.l_b); + eloop_pairs.append(lp); BLI_assert(tot == uid_end - uid_start); UNUSED_VARS_NDEBUG(tot); @@ -311,10 +314,6 @@ static EdgeLoopPair *edbm_ripsel_looptag_helper(BMesh *bm) #endif } - /* null terminate */ - lp = BLI_array_append_ret(eloop_pairs); - lp->l_a = lp->l_b = nullptr; - return eloop_pairs; } @@ -348,32 +347,30 @@ static BMVert *edbm_ripsel_edloop_pair_start_vert(BMEdge *e) } static void edbm_ripsel_deselect_helper(BMesh *bm, - EdgeLoopPair *eloop_pairs, + const Span eloop_pairs, ARegion *region, float projectMat[4][4], const float fmval[2]) { - EdgeLoopPair *lp; - - for (lp = eloop_pairs; lp->l_a; lp++) { + for (const EdgeLoopPair &lp : eloop_pairs) { BMEdge *e; BMVert *v_prev; float score_a = 0.0f; float score_b = 0.0f; - e = lp->l_a->e; + e = lp.l_a->e; v_prev = edbm_ripsel_edloop_pair_start_vert(e); for (; e; e = edbm_ripsel_edge_uid_step(e, &v_prev)) { score_a += edbm_rip_edge_side_measure(e, e->l, region, projectMat, fmval); } - e = lp->l_b->e; + e = lp.l_b->e; v_prev = edbm_ripsel_edloop_pair_start_vert(e); for (; e; e = edbm_ripsel_edge_uid_step(e, &v_prev)) { score_b += edbm_rip_edge_side_measure(e, e->l, region, projectMat, fmval); } - e = (score_a > score_b) ? lp->l_a->e : lp->l_b->e; + e = (score_a > score_b) ? lp.l_a->e : lp.l_b->e; v_prev = edbm_ripsel_edloop_pair_start_vert(e); for (; e; e = edbm_ripsel_edge_uid_step(e, &v_prev)) { BM_edge_select_set(bm, e, false); @@ -903,12 +900,10 @@ static int edbm_rip_invoke__edge(bContext *C, const wmEvent *event, Object *obed const int totedge_orig = bm->totedge; float projectMat[4][4], fmval[3] = {float(event->mval[0]), float(event->mval[1])}; - EdgeLoopPair *eloop_pairs; - ED_view3d_ob_project_mat_get(rv3d, obedit, projectMat); /* important this runs on the original selection, before tampering with tagging */ - eloop_pairs = edbm_ripsel_looptag_helper(bm); + Vector eloop_pairs = edbm_ripsel_looptag_helper(bm); /* expand edge selection */ BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) { @@ -998,7 +993,6 @@ static int edbm_rip_invoke__edge(bContext *C, const wmEvent *event, Object *obed * as expected (but not crash), however there are checks to ensure * tagged edges will split. So far its not been an issue. */ edbm_ripsel_deselect_helper(bm, eloop_pairs, region, projectMat, fmval); - MEM_freeN(eloop_pairs); /* deselect loose verts */ BM_mesh_select_mode_clean_ex(bm, SCE_SELECT_EDGE); diff --git a/source/blender/editors/object/object_vgroup.cc b/source/blender/editors/object/object_vgroup.cc index 067372881f1..5e9ee28e228 100644 --- a/source/blender/editors/object/object_vgroup.cc +++ b/source/blender/editors/object/object_vgroup.cc @@ -22,7 +22,6 @@ #include "DNA_scene_types.h" #include "DNA_workspace_types.h" -#include "BLI_array.h" #include "BLI_array.hh" #include "BLI_bitmap.h" #include "BLI_blenlib.h" diff --git a/source/blender/editors/space_node/node_templates.cc b/source/blender/editors/space_node/node_templates.cc index 127da55fcf6..ef91453bd39 100644 --- a/source/blender/editors/space_node/node_templates.cc +++ b/source/blender/editors/space_node/node_templates.cc @@ -15,7 +15,6 @@ #include "DNA_node_types.h" #include "DNA_screen_types.h" -#include "BLI_array.h" #include "BLI_listbase.h" #include "BLI_string.h" #include "BLI_string_utf8.h" diff --git a/source/blender/editors/space_view3d/view3d_snap.cc b/source/blender/editors/space_view3d/view3d_snap.cc index 205cae7ca9e..7bda595f982 100644 --- a/source/blender/editors/space_view3d/view3d_snap.cc +++ b/source/blender/editors/space_view3d/view3d_snap.cc @@ -11,10 +11,10 @@ #include "DNA_armature_types.h" #include "DNA_object_types.h" -#include "BLI_array.h" #include "BLI_math_matrix.h" #include "BLI_math_vector.h" #include "BLI_utildefines.h" +#include "BLI_vector.hh" #include "BKE_action.h" #include "BKE_armature.h" @@ -46,6 +46,8 @@ #include "view3d_intern.h" +using blender::Vector; + static bool snap_curs_to_sel_ex(bContext *C, const int pivot_point, float r_cursor[3]); static bool snap_calc_active_center(bContext *C, const bool select_only, float r_center[3]); @@ -183,40 +185,32 @@ static int snap_sel_to_grid_exec(bContext *C, wmOperator * /*op*/) XFormObjectData_Container *xds = nullptr; /* Build object array. */ - Object **objects_eval = nullptr; - uint objects_eval_len; + Vector objects_eval; { - BLI_array_declare(objects_eval); FOREACH_SELECTED_EDITABLE_OBJECT_BEGIN (view_layer_eval, v3d, ob_eval) { - BLI_array_append(objects_eval, ob_eval); + objects_eval.append(ob_eval); } FOREACH_SELECTED_EDITABLE_OBJECT_END; - objects_eval_len = BLI_array_len(objects_eval); } if (use_transform_skip_children) { ViewLayer *view_layer = CTX_data_view_layer(C); - Object **objects = static_cast( - MEM_malloc_arrayN(objects_eval_len, sizeof(*objects), __func__)); - - for (int ob_index = 0; ob_index < objects_eval_len; ob_index++) { - Object *ob_eval = objects_eval[ob_index]; - objects[ob_index] = DEG_get_original_object(ob_eval); + Vector objects(objects_eval.size()); + for (Object *ob_eval : objects_eval) { + objects.append_unchecked(DEG_get_original_object(ob_eval)); } BKE_scene_graph_evaluated_ensure(depsgraph, bmain); xcs = ED_object_xform_skip_child_container_create(); ED_object_xform_skip_child_container_item_ensure_from_array( - xcs, scene, view_layer, objects, objects_eval_len); - MEM_freeN(objects); + xcs, scene, view_layer, objects.data(), objects.size()); } if (use_transform_data_origin) { BKE_scene_graph_evaluated_ensure(depsgraph, bmain); xds = ED_object_data_xform_container_create(); } - for (int ob_index = 0; ob_index < objects_eval_len; ob_index++) { - Object *ob_eval = objects_eval[ob_index]; + for (Object *ob_eval : objects_eval) { Object *ob = DEG_get_original_object(ob_eval); vec[0] = -ob_eval->object_to_world[3][0] + gridf * floorf(0.5f + ob_eval->object_to_world[3][0] / gridf); @@ -252,10 +246,6 @@ static int snap_sel_to_grid_exec(bContext *C, wmOperator * /*op*/) DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM); } - if (objects_eval) { - MEM_freeN(objects_eval); - } - if (use_transform_skip_children) { ED_object_xform_skip_child_container_update_all(xcs, bmain, depsgraph); ED_object_xform_skip_child_container_destroy(xcs); @@ -472,16 +462,13 @@ static bool snap_selected_to_location(bContext *C, /* Build object array, tag objects we're transforming. */ ViewLayer *view_layer = CTX_data_view_layer(C); - Object **objects = nullptr; - uint objects_len; + Vector objects; { - BLI_array_declare(objects); FOREACH_SELECTED_EDITABLE_OBJECT_BEGIN (view_layer, v3d, ob) { - BLI_array_append(objects, ob); + objects.append(ob); ob->flag |= OB_DONE; } FOREACH_SELECTED_EDITABLE_OBJECT_END; - objects_len = BLI_array_len(objects); } const bool use_transform_skip_children = use_toolsettings && @@ -497,7 +484,7 @@ static bool snap_selected_to_location(bContext *C, BKE_scene_graph_evaluated_ensure(depsgraph, bmain); xcs = ED_object_xform_skip_child_container_create(); ED_object_xform_skip_child_container_item_ensure_from_array( - xcs, scene, view_layer, objects, objects_len); + xcs, scene, view_layer, objects.data(), objects.size()); } if (use_transform_data_origin) { BKE_scene_graph_evaluated_ensure(depsgraph, bmain); @@ -505,14 +492,12 @@ static bool snap_selected_to_location(bContext *C, /* Initialize the transform data in a separate loop because the depsgraph * may be evaluated while setting the locations. */ - for (int ob_index = 0; ob_index < objects_len; ob_index++) { - Object *ob = objects[ob_index]; + for (Object *ob : objects) { ED_object_data_xform_container_item_ensure(xds, ob); } } - for (int ob_index = 0; ob_index < objects_len; ob_index++) { - Object *ob = objects[ob_index]; + for (Object *ob : objects) { if (ob->parent && BKE_object_flag_test_recursive(ob->parent, OB_DONE)) { continue; } @@ -561,10 +546,6 @@ static bool snap_selected_to_location(bContext *C, DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM); } - if (objects) { - MEM_freeN(objects); - } - if (use_transform_skip_children) { ED_object_xform_skip_child_container_update_all(xcs, bmain, depsgraph); ED_object_xform_skip_child_container_destroy(xcs);