when the size of an edgehash is known or can be guessed,
pass in the argument to reserve the size.
This commit is contained in:
@@ -2405,7 +2405,7 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap, const int
|
||||
STACK_DECLARE(mpoly);
|
||||
STACK_DECLARE(oldp);
|
||||
|
||||
EdgeHash *ehash = BLI_edgehash_new(__func__);
|
||||
EdgeHash *ehash = BLI_edgehash_new_ex(__func__, totedge);
|
||||
|
||||
int i, j, c;
|
||||
|
||||
@@ -2607,10 +2607,12 @@ void CDDM_calc_edges_tessface(DerivedMesh *dm)
|
||||
EdgeHashIterator *ehi;
|
||||
MFace *mf = cddm->mface;
|
||||
MEdge *med;
|
||||
EdgeHash *eh = BLI_edgehash_new(__func__);
|
||||
int i, *index, numEdges, maxFaces = dm->numTessFaceData;
|
||||
EdgeHash *eh;
|
||||
int i, *index, numEdges, numFaces = dm->numTessFaceData;
|
||||
|
||||
for (i = 0; i < maxFaces; i++, mf++) {
|
||||
eh = BLI_edgehash_new_ex(__func__, BLI_EDGEHASH_SIZE_GUESS_FROM_POLYS(numFaces));
|
||||
|
||||
for (i = 0; i < numFaces; i++, mf++) {
|
||||
if (!BLI_edgehash_haskey(eh, mf->v1, mf->v2))
|
||||
BLI_edgehash_insert(eh, mf->v1, mf->v2, NULL);
|
||||
if (!BLI_edgehash_haskey(eh, mf->v2, mf->v3))
|
||||
@@ -2668,21 +2670,27 @@ void CDDM_calc_edges(DerivedMesh *dm)
|
||||
MPoly *mp = cddm->mpoly;
|
||||
MLoop *ml;
|
||||
MEdge *med, *origmed;
|
||||
EdgeHash *eh = BLI_edgehash_new(__func__);
|
||||
EdgeHash *eh;
|
||||
unsigned int eh_reserve;
|
||||
int v1, v2;
|
||||
int *eindex;
|
||||
int i, j, *index, numEdges = cddm->dm.numEdgeData, maxFaces = dm->numPolyData;
|
||||
int i, j, *index;
|
||||
const int numFaces = dm->numPolyData;
|
||||
const int numLoops = dm->numLoopData;
|
||||
int numEdges = dm->numEdgeData;
|
||||
|
||||
eindex = DM_get_edge_data_layer(dm, CD_ORIGINDEX);
|
||||
|
||||
med = cddm->medge;
|
||||
|
||||
eh_reserve = max_ii(med ? numEdges : 0, BLI_EDGEHASH_SIZE_GUESS_FROM_LOOPS(numLoops));
|
||||
eh = BLI_edgehash_new_ex(__func__, eh_reserve);
|
||||
if (med) {
|
||||
for (i = 0; i < numEdges; i++, med++) {
|
||||
BLI_edgehash_insert(eh, med->v1, med->v2, SET_INT_IN_POINTER(i + 1));
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < maxFaces; i++, mp++) {
|
||||
for (i = 0; i < numFaces; i++, mp++) {
|
||||
ml = cddm->mloop + mp->loopstart;
|
||||
for (j = 0; j < mp->totloop; j++, ml++) {
|
||||
v1 = ml->v;
|
||||
@@ -2732,7 +2740,7 @@ void CDDM_calc_edges(DerivedMesh *dm)
|
||||
cddm->medge = CustomData_get_layer(&dm->edgeData, CD_MEDGE);
|
||||
|
||||
mp = cddm->mpoly;
|
||||
for (i = 0; i < maxFaces; i++, mp++) {
|
||||
for (i = 0; i < numFaces; i++, mp++) {
|
||||
ml = cddm->mloop + mp->loopstart;
|
||||
for (j = 0; j < mp->totloop; j++, ml++) {
|
||||
v1 = ml->v;
|
||||
|
@@ -177,8 +177,8 @@ static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2
|
||||
if (l1->type == CD_MEDGE) {
|
||||
MEdge *e1 = l1->data;
|
||||
MEdge *e2 = l2->data;
|
||||
EdgeHash *eh = BLI_edgehash_new(__func__);
|
||||
int etot = m1->totedge;
|
||||
EdgeHash *eh = BLI_edgehash_new_ex(__func__, etot);
|
||||
|
||||
for (j = 0; j < etot; j++, e1++) {
|
||||
BLI_edgehash_insert(eh, e1->v1, e1->v2, e1);
|
||||
|
@@ -921,7 +921,8 @@ void BKE_mesh_calc_edges(Mesh *mesh, bool update, const bool select)
|
||||
EdgeHashIterator *ehi;
|
||||
MPoly *mp;
|
||||
MEdge *med, *med_orig;
|
||||
EdgeHash *eh = BLI_edgehash_new(__func__);
|
||||
EdgeHash *eh;
|
||||
unsigned int eh_reserve;
|
||||
int i, totedge, totpoly = mesh->totpoly;
|
||||
int med_index;
|
||||
/* select for newly created meshes which are selected [#25595] */
|
||||
@@ -930,6 +931,9 @@ void BKE_mesh_calc_edges(Mesh *mesh, bool update, const bool select)
|
||||
if (mesh->totedge == 0)
|
||||
update = false;
|
||||
|
||||
eh_reserve = max_ii(update ? mesh->totedge : 0, BLI_EDGEHASH_SIZE_GUESS_FROM_POLYS(totpoly));
|
||||
eh = BLI_edgehash_new_ex(__func__, eh_reserve);
|
||||
|
||||
if (update) {
|
||||
/* assume existing edges are valid
|
||||
* useful when adding more faces and generating edges from them */
|
||||
|
@@ -2484,7 +2484,7 @@ static EdgeHash *sph_springhash_build(ParticleSystem *psys)
|
||||
ParticleSpring *spring;
|
||||
int i = 0;
|
||||
|
||||
springhash = BLI_edgehash_new(__func__);
|
||||
springhash = BLI_edgehash_new_ex(__func__, psys->tot_fluidsprings);
|
||||
|
||||
for (i=0, spring=psys->fluid_springs; i<psys->tot_fluidsprings; i++, spring++)
|
||||
BLI_edgehash_insert(springhash, spring->particle_index[0], spring->particle_index[1], SET_INT_IN_POINTER(i+1));
|
||||
|
@@ -334,7 +334,7 @@ static int ss_sync_from_uv(CCGSubSurf *ss, CCGSubSurf *origss, DerivedMesh *dm,
|
||||
}
|
||||
|
||||
/* create edges */
|
||||
ehash = BLI_edgehash_new(__func__);
|
||||
ehash = BLI_edgehash_new_ex(__func__, BLI_EDGEHASH_SIZE_GUESS_FROM_POLYS(totface));
|
||||
|
||||
for (i = 0; i < totface; i++) {
|
||||
MPoly *mp = &((MPoly *) mpoly)[i];
|
||||
|
@@ -62,4 +62,8 @@ void BLI_edgehashIterator_setValue(EdgeHashIterator *ehi, void *v
|
||||
void BLI_edgehashIterator_step(EdgeHashIterator *ehi);
|
||||
bool BLI_edgehashIterator_isDone(EdgeHashIterator *ehi);
|
||||
|
||||
#define BLI_EDGEHASH_SIZE_GUESS_FROM_LOOPS(totloop) ((totloop) / 2)
|
||||
#define BLI_EDGEHASH_SIZE_GUESS_FROM_POLYS(totpoly) ((totpoly) * 2)
|
||||
|
||||
|
||||
#endif
|
||||
|
@@ -281,7 +281,7 @@ static void laplacian_system_construct_end(LaplacianSystem *sys)
|
||||
|
||||
sys->varea = MEM_callocN(sizeof(float) * totvert, "LaplacianSystemVarea");
|
||||
|
||||
sys->edgehash = BLI_edgehash_new(__func__);
|
||||
sys->edgehash = BLI_edgehash_new_ex(__func__, BLI_EDGEHASH_SIZE_GUESS_FROM_POLYS(sys->totface));
|
||||
for (a = 0, face = sys->faces; a < sys->totface; a++, face++) {
|
||||
laplacian_increase_edge_count(sys->edgehash, (*face)[0], (*face)[1]);
|
||||
laplacian_increase_edge_count(sys->edgehash, (*face)[1], (*face)[2]);
|
||||
|
Reference in New Issue
Block a user