replace BLI_array_growone() with BLI_array_growitems() when the size of the increase is known ahead of time, will reduce reallocs and give some speedup.

This commit is contained in:
Campbell Barton 2012-01-23 13:51:44 +00:00
parent 001a15a721
commit 41c0f0c733
8 changed files with 32 additions and 33 deletions

@ -1112,8 +1112,8 @@ void DM_update_weight_mcol(Object *ob, DerivedMesh *dm, int const draw_flag,
for (i=0; i<dm->numPolyData; i++, mp++) { for (i=0; i<dm->numPolyData; i++, mp++) {
ml = mloop + mp->loopstart; ml = mloop + mp->loopstart;
for (j=0; j<mp->totloop; j++, ml++, totloop++) { BLI_array_growitems(wtcol_l, mp->totloop);
BLI_array_growone(wtcol_l); for (j = 0; j < mp->totloop; j++, ml++, totloop++) {
copy_v4_v4_char((char *)&wtcol_l[totloop], copy_v4_v4_char((char *)&wtcol_l[totloop],
(char *)&wtcol_v[4 * ml->v]); (char *)&wtcol_v[4 * ml->v]);
} }

@ -171,10 +171,11 @@ BMEditMesh *CDDM_To_BMesh(Object *ob, DerivedMesh *dm, BMEditMesh *existing, int
BLI_array_empty(verts); BLI_array_empty(verts);
BLI_array_empty(edges); BLI_array_empty(edges);
BLI_array_growitems(verts, mp->totloop);
BLI_array_growitems(edges, mp->totloop);
ml = mloop + mp->loopstart; ml = mloop + mp->loopstart;
for (j=0; j<mp->totloop; j++, ml++) { for (j = 0; j < mp->totloop; j++, ml++) {
BLI_array_growone(verts);
BLI_array_growone(edges);
verts[j] = vtable[ml->v]; verts[j] = vtable[ml->v];
edges[j] = etable[ml->e]; edges[j] = etable[ml->e];

@ -3040,17 +3040,16 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
/* set the face base vert */ /* set the face base vert */
*((int*)ccgSubSurf_getFaceUserData(ss, f)) = vertNum; *((int*)ccgSubSurf_getFaceUserData(ss, f)) = vertNum;
BLI_array_empty(loopidx); BLI_array_empty(loopidx);
for (s=0; s<numVerts; s++) { BLI_array_growitems(loopidx, numVerts);
BLI_array_growone(loopidx); for (s = 0; s < numVerts; s++) {
loopidx[s] = loopindex++; loopidx[s] = loopindex++;
} }
BLI_array_empty(vertidx); BLI_array_empty(vertidx);
for(s = 0; s < numVerts; s++) { BLI_array_growitems(vertidx, numVerts);
for (s = 0; s < numVerts; s++) {
CCGVert *v = ccgSubSurf_getFaceVert(ss, f, s); CCGVert *v = ccgSubSurf_getFaceVert(ss, f, s);
BLI_array_growone(vertidx);
vertidx[s] = GET_INT_FROM_POINTER(ccgSubSurf_getVertVertHandle(v)); vertidx[s] = GET_INT_FROM_POINTER(ccgSubSurf_getVertVertHandle(v));
} }

@ -528,10 +528,11 @@ BMesh *BM_Copy_Mesh(BMesh *bmold)
BLI_array_empty(loops); BLI_array_empty(loops);
BLI_array_empty(edges); BLI_array_empty(edges);
BLI_array_growitems(loops, f->len);
BLI_array_growitems(edges, f->len);
l = BMIter_New(&liter, bmold, BM_LOOPS_OF_FACE, f); l = BMIter_New(&liter, bmold, BM_LOOPS_OF_FACE, f);
for (j=0; j<f->len; j++, l = BMIter_Step(&liter)) { for (j=0; j<f->len; j++, l = BMIter_Step(&liter)) {
BLI_array_growone(loops);
BLI_array_growone(edges);
loops[j] = l; loops[j] = l;
edges[j] = etable[BM_GetIndex(l->e)]; edges[j] = etable[BM_GetIndex(l->e)];
} }

@ -239,10 +239,10 @@ static void edgering_sel(tringselOpData *lcd, int previewlines, int select)
co[1][0] = (v[1][1]->co[0] - v[1][0]->co[0])*(i/((float)previewlines+1))+v[1][0]->co[0]; co[1][0] = (v[1][1]->co[0] - v[1][0]->co[0])*(i/((float)previewlines+1))+v[1][0]->co[0];
co[1][1] = (v[1][1]->co[1] - v[1][0]->co[1])*(i/((float)previewlines+1))+v[1][0]->co[1]; co[1][1] = (v[1][1]->co[1] - v[1][0]->co[1])*(i/((float)previewlines+1))+v[1][0]->co[1];
co[1][2] = (v[1][1]->co[2] - v[1][0]->co[2])*(i/((float)previewlines+1))+v[1][0]->co[2]; co[1][2] = (v[1][1]->co[2] - v[1][0]->co[2])*(i/((float)previewlines+1))+v[1][0]->co[2];
BLI_array_growone(edges); BLI_array_growone(edges);
VECCOPY(edges[tot][0], co[0]); copy_v3_v3(edges[tot][0], co[0]);
VECCOPY(edges[tot][1], co[1]); copy_v3_v3(edges[tot][1], co[1]);
tot++; tot++;
} }
} }

@ -187,12 +187,12 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe
BLI_array_empty(tf_uv); BLI_array_empty(tf_uv);
BLI_array_empty(tf_uvorig); BLI_array_empty(tf_uvorig);
BLI_array_growitems(tf_uv, efa->len);
BLI_array_growitems(tf_uvorig, efa->len);
i = 0; i = 0;
BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) { BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) {
luv= CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); luv= CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
BLI_array_growone(tf_uv);
BLI_array_growone(tf_uvorig);
tf_uvorig[i][0] = luv->uv[0]; tf_uvorig[i][0] = luv->uv[0];
tf_uvorig[i][1] = luv->uv[1]; tf_uvorig[i][1] = luv->uv[1];
@ -238,12 +238,12 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe
BLI_array_empty(tf_uv); BLI_array_empty(tf_uv);
BLI_array_empty(tf_uvorig); BLI_array_empty(tf_uvorig);
BLI_array_growitems(tf_uv, efa->len);
BLI_array_growitems(tf_uvorig, efa->len);
i = 0; i = 0;
BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) { BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) {
luv= CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); luv= CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
BLI_array_growone(tf_uv);
BLI_array_growone(tf_uvorig);
tf_uvorig[i][0] = luv->uv[0]; tf_uvorig[i][0] = luv->uv[0];
tf_uvorig[i][1] = luv->uv[1]; tf_uvorig[i][1] = luv->uv[1];

@ -1953,9 +1953,9 @@ static int mouse_select(bContext *C, float co[2], int extend, int loop)
} }
/* mark 1 vertex as being hit */ /* mark 1 vertex as being hit */
BLI_array_growitems(hitv, hit.efa->len);
BLI_array_growitems(hituv, hit.efa->len);
for(i=0; i<hit.efa->len; i++) { for(i=0; i<hit.efa->len; i++) {
BLI_array_growone(hitv);
BLI_array_growone(hituv);
hitv[i]= 0xFFFFFFFF; hitv[i]= 0xFFFFFFFF;
} }
@ -1974,9 +1974,9 @@ static int mouse_select(bContext *C, float co[2], int extend, int loop)
} }
/* mark 2 edge vertices as being hit */ /* mark 2 edge vertices as being hit */
for(i=0; i<hit.efa->len; i++) { BLI_array_growitems(hitv, hit.efa->len);
BLI_array_growone(hitv); BLI_array_growitems(hituv, hit.efa->len);
BLI_array_growone(hituv); for (i=0; i < hit.efa->len; i++) {
hitv[i]= 0xFFFFFFFF; hitv[i]= 0xFFFFFFFF;
} }
@ -2002,12 +2002,12 @@ static int mouse_select(bContext *C, float co[2], int extend, int loop)
BM_set_actFace(em->bm, hit.efa); BM_set_actFace(em->bm, hit.efa);
/* mark all face vertices as being hit */ /* mark all face vertices as being hit */
BLI_array_growitems(hitv, hit.efa->len);
BLI_array_growitems(hituv, hit.efa->len);
i = 0; i = 0;
BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, hit.efa) { BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, hit.efa) {
luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
BLI_array_growone(hitv);
BLI_array_growone(hituv);
hituv[i]= luv->uv; hituv[i]= luv->uv;
hitv[i] = BM_GetIndex(l->v); hitv[i] = BM_GetIndex(l->v);
i++; i++;

@ -1409,16 +1409,14 @@ static void uv_map_mirror(BMEditMesh *em, BMFace *efa, MTexPoly *UNUSED(tf))
BMLoop *l; BMLoop *l;
BMIter liter; BMIter liter;
MLoopUV *luv; MLoopUV *luv;
BLI_array_declare(uvs);
float **uvs = NULL; float **uvs = NULL;
BLI_array_fixedstack_declare(uvs, BM_NGON_STACK_SIZE, efa->len, __func__);
float dx; float dx;
int i, mi; int i, mi;
i = 0; i = 0;
BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) { BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) {
luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
BLI_array_growone(uvs);
uvs[i] = luv->uv; uvs[i] = luv->uv;
i++; i++;
} }
@ -1435,7 +1433,7 @@ static void uv_map_mirror(BMEditMesh *em, BMFace *efa, MTexPoly *UNUSED(tf))
} }
} }
BLI_array_free(uvs); BLI_array_fixedstack_free(uvs);
} }
static int sphere_project_exec(bContext *C, wmOperator *op) static int sphere_project_exec(bContext *C, wmOperator *op)