[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [52890] trunk/blender/source/blender: replace BLI_array_fixedstack_declare with() new macro BLI_array_alloca() which uses stack memory always and doesn't need to be freed explicitly.
Campbell Barton
ideasman42 at gmail.com
Tue Dec 11 16:10:20 CET 2012
Revision: 52890
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=52890
Author: campbellbarton
Date: 2012-12-11 15:10:19 +0000 (Tue, 11 Dec 2012)
Log Message:
-----------
replace BLI_array_fixedstack_declare with() new macro BLI_array_alloca() which uses stack memory always and doesn't need to be freed explicitly.
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/intern/mesh.c
trunk/blender/source/blender/blenlib/BLI_array.h
trunk/blender/source/blender/bmesh/intern/bmesh_construct.c
trunk/blender/source/blender/bmesh/intern/bmesh_core.c
trunk/blender/source/blender/bmesh/intern/bmesh_interp.c
trunk/blender/source/blender/bmesh/intern/bmesh_polygon.c
trunk/blender/source/blender/bmesh/intern/bmesh_queries.c
trunk/blender/source/blender/bmesh/operators/bmo_extrude.c
trunk/blender/source/blender/bmesh/tools/bmesh_bevel.c
trunk/blender/source/blender/editors/mesh/editmesh_knife.c
trunk/blender/source/blender/editors/uvedit/uvedit_unwrap_ops.c
Modified: trunk/blender/source/blender/blenkernel/intern/mesh.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/mesh.c 2012-12-11 15:06:51 UTC (rev 52889)
+++ trunk/blender/source/blender/blenkernel/intern/mesh.c 2012-12-11 15:10:19 UTC (rev 52890)
@@ -3009,9 +3009,9 @@
else {
int i;
MLoop *l_iter = loopstart;
- float area, polynorm_local[3], (*vertexcos)[3];
+ float area, polynorm_local[3];
+ float (*vertexcos)[3] = BLI_array_alloca(vertexcos, mpoly->totloop);
const float *no = polynormal ? polynormal : polynorm_local;
- BLI_array_fixedstack_declare(vertexcos, BM_DEFAULT_NGON_STACK_SIZE, mpoly->totloop, __func__);
/* pack vertex cos into an array for area_poly_v3 */
for (i = 0; i < mpoly->totloop; i++, l_iter++) {
@@ -3026,8 +3026,6 @@
/* finally calculate the area */
area = area_poly_v3(mpoly->totloop, vertexcos, no);
- BLI_array_fixedstack_free(vertexcos);
-
return area;
}
}
Modified: trunk/blender/source/blender/blenlib/BLI_array.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_array.h 2012-12-11 15:06:51 UTC (rev 52889)
+++ trunk/blender/source/blender/blenlib/BLI_array.h 2012-12-11 15:10:19 UTC (rev 52890)
@@ -196,3 +196,22 @@
if (_##arr##_is_static) { \
MEM_freeN(arr); \
} (void)0
+
+
+/* alloca */
+#if defined(__GNUC__) || defined(__clang__)
+#define BLI_array_alloca(arr, realsize) \
+ (typeof(arr))alloca(sizeof(*arr) * (realsize))
+
+#define BLI_array_alloca_and_count(arr, realsize) \
+ (typeof(arr))alloca(sizeof(*arr) * (realsize)); \
+ const int _##arr##_count = (realsize)
+
+#else
+#define BLI_array_alloca(arr, realsize) \
+ alloca(sizeof(*arr) * (realsize))
+
+#define BLI_array_alloca_and_count(arr, realsize) \
+ alloca(sizeof(*arr) * (realsize)); \
+ const int _##arr##_count = (realsize)
+#endif
Modified: trunk/blender/source/blender/bmesh/intern/bmesh_construct.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_construct.c 2012-12-11 15:06:51 UTC (rev 52889)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_construct.c 2012-12-11 15:10:19 UTC (rev 52890)
@@ -173,15 +173,17 @@
*/
BMFace *BM_face_create_ngon(BMesh *bm, BMVert *v1, BMVert *v2, BMEdge **edges, int len, const int create_flag)
{
- BMEdge **edges2 = NULL;
- BLI_array_staticdeclare(edges2, BM_DEFAULT_NGON_STACK_SIZE);
- BMVert **verts = NULL;
- BLI_array_staticdeclare(verts, BM_DEFAULT_NGON_STACK_SIZE);
+ BMEdge **edges2 = BLI_array_alloca_and_count(edges2, len);
+ BMVert **verts = BLI_array_alloca_and_count(verts, len + 1);
+ int e2_index = 0;
+ int v_index = 0;
+
BMFace *f = NULL;
BMEdge *e;
BMVert *v, *ev1, *ev2;
int i, /* j, */ v1found, reverse;
+
/* this code is hideous, yeek. I'll have to think about ways of
* cleaning it up. basically, it now combines the old BM_face_create_ngon
* _and_ the old bmesh_mf functions, so its kindof smashed together
@@ -207,14 +209,14 @@
SWAP(BMVert *, ev1, ev2);
}
- BLI_array_append(verts, ev1);
+ verts[v_index++] = ev1;
v = ev2;
e = edges[0];
do {
BMEdge *e2 = e;
- BLI_array_append(verts, v);
- BLI_array_append(edges2, e);
+ verts[v_index++] = v;
+ edges2[e2_index++] = e;
/* we only flag the verts to check if they are in the face more then once */
BM_ELEM_API_FLAG_ENABLE(v, _FLAG_MV);
@@ -289,9 +291,6 @@
BM_ELEM_API_FLAG_DISABLE(edges2[i], _FLAG_MF);
}
- BLI_array_free(verts);
- BLI_array_free(edges2);
-
return f;
err:
@@ -303,9 +302,6 @@
}
}
- BLI_array_free(verts);
- BLI_array_free(edges2);
-
return NULL;
}
Modified: trunk/blender/source/blender/bmesh/intern/bmesh_core.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_core.c 2012-12-11 15:06:51 UTC (rev 52889)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_core.c 2012-12-11 15:10:19 UTC (rev 52890)
@@ -211,10 +211,8 @@
BMFace *BM_face_copy(BMesh *bm, BMFace *f, const short copyverts, const short copyedges)
{
- BMVert **verts = NULL;
- BMEdge **edges = NULL;
- BLI_array_fixedstack_declare(verts, BM_DEFAULT_NGON_STACK_SIZE, f->len, __func__);
- BLI_array_fixedstack_declare(edges, BM_DEFAULT_NGON_STACK_SIZE, f->len, __func__);
+ BMVert **verts = BLI_array_alloca(verts, f->len);
+ BMEdge **edges = BLI_array_alloca(edges, f->len);
BMLoop *l_iter;
BMLoop *l_first;
BMLoop *l_copy;
@@ -267,9 +265,6 @@
l_copy = l_copy->next;
} while ((l_iter = l_iter->next) != l_first);
- BLI_array_fixedstack_free(verts);
- BLI_array_fixedstack_free(edges);
-
return f_copy;
}
@@ -585,22 +580,19 @@
*/
void BM_face_edges_kill(BMesh *bm, BMFace *f)
{
- BMEdge **edges = NULL;
- BLI_array_staticdeclare(edges, BM_DEFAULT_NGON_STACK_SIZE);
+ BMEdge **edges = BLI_array_alloca_and_count(edges, f->len);
BMLoop *l_iter;
BMLoop *l_first;
- int i;
+ int i = 0;
l_iter = l_first = BM_FACE_FIRST_LOOP(f);
do {
- BLI_array_append(edges, l_iter->e);
+ edges[i++] = l_iter->e;
} while ((l_iter = l_iter->next) != l_first);
for (i = 0; i < BLI_array_count(edges); i++) {
BM_edge_kill(bm, edges[i]);
}
-
- BLI_array_free(edges);
}
/**
@@ -609,22 +601,19 @@
*/
void BM_face_verts_kill(BMesh *bm, BMFace *f)
{
- BMVert **verts = NULL;
- BLI_array_staticdeclare(verts, BM_DEFAULT_NGON_STACK_SIZE);
+ BMVert **verts = BLI_array_alloca_and_count(verts, f->len);
BMLoop *l_iter;
BMLoop *l_first;
- int i;
+ int i = 0;
l_iter = l_first = BM_FACE_FIRST_LOOP(f);
do {
- BLI_array_append(verts, l_iter->v);
+ verts[i++] = l_iter->v;
} while ((l_iter = l_iter->next) != l_first);
for (i = 0; i < BLI_array_count(verts); i++) {
BM_vert_kill(bm, verts[i]);
}
-
- BLI_array_free(verts);
}
/**
@@ -761,8 +750,7 @@
const int len = f->len;
const int do_disps = CustomData_has_layer(&bm->ldata, CD_MDISPS);
BMLoop *l_iter, *oldprev, *oldnext;
- BMEdge **edar = NULL;
- BLI_array_fixedstack_declare(edar, BM_DEFAULT_NGON_STACK_SIZE, len, __func__);
+ BMEdge **edar = BLI_array_alloca(edar, len);
int i, j, edok;
for (i = 0, l_iter = l_first; i < len; i++, l_iter = l_iter->next) {
@@ -826,8 +814,6 @@
BM_CHECK_ELEMENT(l_iter->f);
}
- BLI_array_fixedstack_free(edar);
-
BM_CHECK_ELEMENT(f);
return 1;
@@ -1614,8 +1600,7 @@
radlen = bmesh_radial_length(ke->l);
if (LIKELY(radlen)) {
- BMLoop **loops = NULL;
- BLI_array_fixedstack_declare(loops, BM_DEFAULT_NGON_STACK_SIZE, radlen, __func__);
+ BMLoop **loops = BLI_array_alloca(loops, radlen);
killoop = ke->l;
@@ -1628,7 +1613,6 @@
bm->totloop--;
BLI_mempool_free(bm->lpool, loops[i]);
}
- BLI_array_fixedstack_free(loops);
}
/* Validate radial cycle of oe */
Modified: trunk/blender/source/blender/bmesh/intern/bmesh_interp.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_interp.c 2012-12-11 15:06:51 UTC (rev 52889)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_interp.c 2012-12-11 15:10:19 UTC (rev 52890)
@@ -172,11 +172,9 @@
BMLoop *l_iter;
BMLoop *l_first;
- void **blocks = NULL;
- float (*cos)[3] = NULL, *w = NULL;
- BLI_array_fixedstack_declare(cos, BM_DEFAULT_NGON_STACK_SIZE, source->len, __func__);
- BLI_array_fixedstack_declare(w, BM_DEFAULT_NGON_STACK_SIZE, source->len, __func__);
- BLI_array_fixedstack_declare(blocks, BM_DEFAULT_NGON_STACK_SIZE, source->len, __func__);
+ void **blocks = BLI_array_alloca(blocks, source->len);
+ float (*cos)[3] = BLI_array_alloca(cos, source->len);
+ float *w = BLI_array_alloca(w, source->len);
int i;
BM_elem_attrs_copy(bm, bm, source, target);
@@ -196,10 +194,6 @@
CustomData_bmesh_interp(&bm->ldata, blocks, w, NULL, source->len, l_iter->head.data);
i++;
} while ((l_iter = l_iter->next) != l_first);
-
- BLI_array_fixedstack_free(cos);
- BLI_array_fixedstack_free(w);
- BLI_array_fixedstack_free(blocks);
}
/**
@@ -609,14 +603,12 @@
{
BMLoop *l_iter;
BMLoop *l_first;
- void **blocks = NULL;
- void **vblocks = NULL;
- float (*cos)[3] = NULL, co[3], *w = NULL;
+ void **vblocks = BLI_array_alloca(vblocks, do_vertex ? source->len : 0);
+ void **blocks = BLI_array_alloca(blocks, source->len);
+ float (*cos)[3] = BLI_array_alloca(cos, source->len);
+ float *w = BLI_array_alloca(w, source->len);
+ float co[3];
float cent[3] = {0.0f, 0.0f, 0.0f};
- BLI_array_fixedstack_declare(cos, BM_DEFAULT_NGON_STACK_SIZE, source->len, __func__);
- BLI_array_fixedstack_declare(w, BM_DEFAULT_NGON_STACK_SIZE, source->len, __func__);
- BLI_array_fixedstack_declare(blocks, BM_DEFAULT_NGON_STACK_SIZE, source->len, __func__);
- BLI_array_fixedstack_declare(vblocks, BM_DEFAULT_NGON_STACK_SIZE, do_vertex ? source->len : 0, __func__);
int i, ax, ay;
BM_elem_attrs_copy(bm, bm, source, target->f);
@@ -667,13 +659,8 @@
CustomData_bmesh_interp(&bm->ldata, blocks, w, NULL, source->len, target->head.data);
if (do_vertex) {
CustomData_bmesh_interp(&bm->vdata, vblocks, w, NULL, source->len, target->v->head.data);
- BLI_array_fixedstack_free(vblocks);
}
- BLI_array_fixedstack_free(cos);
- BLI_array_fixedstack_free(w);
- BLI_array_fixedstack_free(blocks);
-
if (do_multires) {
if (CustomData_has_layer(&bm->ldata, CD_MDISPS)) {
bm_loop_interp_mdisps(bm, target, source);
@@ -686,12 +673,10 @@
{
BMLoop *l_iter;
BMLoop *l_first;
- void **blocks = NULL;
- float (*cos)[3] = NULL, *w = NULL;
+ void **blocks = BLI_array_alloca(blocks, source->len);
+ float (*cos)[3] = BLI_array_alloca(cos, source->len);
+ float *w = BLI_array_alloca(w, source->len);
float cent[3] = {0.0f, 0.0f, 0.0f};
- BLI_array_fixedstack_declare(cos, BM_DEFAULT_NGON_STACK_SIZE, source->len, __func__);
- BLI_array_fixedstack_declare(w, BM_DEFAULT_NGON_STACK_SIZE, source->len, __func__);
- BLI_array_fixedstack_declare(blocks, BM_DEFAULT_NGON_STACK_SIZE, source->len, __func__);
int i;
i = 0;
@@ -718,10 +703,6 @@
/* interpolate */
interp_weights_poly_v3(w, cos, source->len, v->co);
CustomData_bmesh_interp(&bm->vdata, blocks, w, NULL, source->len, v->head.data);
-
- BLI_array_fixedstack_free(cos);
- BLI_array_fixedstack_free(w);
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list