un-inline edgehash functions, BLI_edgehash_insert was far too big to inline.
authorCampbell Barton <ideasman42@gmail.com>
Wed, 28 Dec 2011 10:06:10 +0000 (10:06 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 28 Dec 2011 10:06:10 +0000 (10:06 +0000)
and have edge hash use unsigned ints since edge verts are unsigned ints for MEdge's

source/blender/blenkernel/intern/cdderivedmesh.c
source/blender/blenkernel/intern/mesh_validate.c
source/blender/blenlib/BLI_edgehash.h
source/blender/blenlib/intern/edgehash.c
source/blender/modifiers/intern/MOD_solidify.c

index dca756800b2a782321ad3988748af35948be6115..8ce6c593a1bdbc4102fb45437b10d06c3175d2ca 100644 (file)
@@ -2504,7 +2504,7 @@ void CDDM_calc_edges(DerivedMesh *dm)
        index = CustomData_get_layer(&edgeData, CD_ORIGINDEX);
        for(i = 0; !BLI_edgehashIterator_isDone(ehi);
                BLI_edgehashIterator_step(ehi), ++i, ++med, ++index) {
-               BLI_edgehashIterator_getKey(ehi, (int*)&med->v1, (int*)&med->v2);
+               BLI_edgehashIterator_getKey(ehi, &med->v1, &med->v2);
 
                med->flag = ME_EDGEDRAW|ME_EDGERENDER;
                *index = ORIGINDEX_NONE;
@@ -2567,7 +2567,7 @@ void CDDM_calc_edges_poly(DerivedMesh *dm)
        index = CustomData_get_layer(&edgeData, CD_ORIGINDEX);
        for(i = 0; !BLI_edgehashIterator_isDone(ehi);
            BLI_edgehashIterator_step(ehi), ++i, ++med, ++index) {
-               BLI_edgehashIterator_getKey(ehi, (int*)&med->v1, (int*)&med->v2);
+               BLI_edgehashIterator_getKey(ehi, &med->v1, &med->v2);
                j = GET_INT_FROM_POINTER(BLI_edgehashIterator_getValue(ehi));
 
                med->flag = ME_EDGEDRAW|ME_EDGERENDER;
index 9027896113c5715a5ac0ab45b1bb681de1c5c6ec..92f7f959f8a276f9d326a842f1d027843854102c 100644 (file)
@@ -527,7 +527,7 @@ void BKE_mesh_calc_edges(Mesh *mesh, int update)
                if(update && (med_orig=BLI_edgehashIterator_getValue(ehi))) {
                        *med= *med_orig; /* copy from the original */
                } else {
-                       BLI_edgehashIterator_getKey(ehi, (int*)&med->v1, (int*)&med->v2);
+                       BLI_edgehashIterator_getKey(ehi, &med->v1, &med->v2);
                        med->flag = ME_EDGEDRAW|ME_EDGERENDER|SELECT; /* select for newly created meshes which are selected [#25595] */
                }
 
index 283b52e06b928fa9c9964d76916d2862f14e162e..9153155e359aeed78089900a9835a84d6847b8cc 100644 (file)
@@ -47,22 +47,22 @@ void                        BLI_edgehash_free               (EdgeHash *eh, EdgeHashFreeFP valfreefp);
        /* Insert edge (v0,v1) into hash with given value, does
         * not check for duplicates.
         */
-void                   BLI_edgehash_insert             (EdgeHash *eh, int v0, int v1, void *val);
+void                   BLI_edgehash_insert             (EdgeHash *eh, unsigned int v0, unsigned int v1, void *val);
 
        /* Return value for given edge (v0,v1), or NULL if
         * if key does not exist in hash. (If need exists 
         * to differentiate between key-value being NULL and 
         * lack of key then see BLI_edgehash_lookup_p().
         */
-void*                  BLI_edgehash_lookup             (EdgeHash *eh, int v0, int v1);
+void*                  BLI_edgehash_lookup             (EdgeHash *eh, unsigned int v0, unsigned int v1);
 
        /* Return pointer to value for given edge (v0,v1),
         * or NULL if key does not exist in hash.
         */
-void**                 BLI_edgehash_lookup_p   (EdgeHash *eh, int v0, int v1);
+void**                 BLI_edgehash_lookup_p   (EdgeHash *eh, unsigned int v0, unsigned int v1);
 
        /* Return boolean true/false if edge (v0,v1) in hash. */
-int                            BLI_edgehash_haskey             (EdgeHash *eh, int v0, int v1);
+int                            BLI_edgehash_haskey             (EdgeHash *eh, unsigned int v0, unsigned int v1);
 
        /* Return number of keys in hash. */
 int                            BLI_edgehash_size               (EdgeHash *eh);
@@ -83,7 +83,7 @@ EdgeHashIterator*     BLI_edgehashIterator_new                (EdgeHash *eh);
 void                           BLI_edgehashIterator_free               (EdgeHashIterator *ehi);
 
        /* Retrieve the key from an iterator. */
-void                           BLI_edgehashIterator_getKey             (EdgeHashIterator *ehi, int *v0_r, int *v1_r);
+void                           BLI_edgehashIterator_getKey             (EdgeHashIterator *ehi, unsigned int *v0_r, unsigned int *v1_r);
        
        /* Retrieve the value from an iterator. */
 void*                          BLI_edgehashIterator_getValue   (EdgeHashIterator *ehi);
@@ -98,4 +98,3 @@ void                          BLI_edgehashIterator_step               (EdgeHashIterator *ehi);
 int                                    BLI_edgehashIterator_isDone             (EdgeHashIterator *ehi);
 
 #endif
-
index c646c59ea0e60aa3fefa3e7bab9b4c40005e9ff2..b710e5d496de78989730229252b796a26a30745a 100644 (file)
@@ -48,14 +48,22 @@ static unsigned int _ehash_hashsizes[]= {
        268435459
 };
 
-#define EDGEHASH(v0,v1)                ((v0*39)^(v1*31))
+#define EDGE_HASH(v0, v1)  ((v0 * 39)^(v1 * 31))
+
+/* ensure v0 is smaller */
+#define EDGE_ORD(v0, v1) \
+       if (v0 < v1) {       \
+               v0 ^= v1;        \
+               v1 ^= v0;        \
+               v0 ^= v1;        \
+       }
 
 /***/
 
 typedef struct EdgeEntry EdgeEntry;
 struct EdgeEntry {
        EdgeEntry *next;
-       int v0, v1;
+       unsigned int v0, v1;
        void *val;
 };
 
@@ -69,52 +77,50 @@ struct EdgeHash {
 
 EdgeHash *BLI_edgehash_new(void)
 {
-       EdgeHash *eh= MEM_callocN(sizeof(*eh), "EdgeHash");
-       eh->cursize= 0;
-       eh->nentries= 0;
-       eh->nbuckets= _ehash_hashsizes[eh->cursize];
+       EdgeHash *eh = MEM_callocN(sizeof(*eh), "EdgeHash");
+       eh->cursize = 0;
+       eh->nentries = 0;
+       eh->nbuckets = _ehash_hashsizes[eh->cursize];
        
-       eh->buckets= MEM_callocN(eh->nbuckets*sizeof(*eh->buckets), "eh buckets 2");
+       eh->buckets = MEM_callocN(eh->nbuckets * sizeof(*eh->buckets), "eh buckets 2");
        eh->epool = BLI_mempool_create(sizeof(EdgeEntry), 512, 512, TRUE, FALSE);
 
        return eh;
 }
 
 
-void BLI_edgehash_insert(EdgeHash *eh, int v0, int v1, void *val) {
+void BLI_edgehash_insert(EdgeHash *eh, unsigned int v0, unsigned int v1, void *val)
+{
        unsigned int hash;
-       EdgeEntry *e= BLI_mempool_alloc(eh->epool);
+       EdgeEntry *e = BLI_mempool_alloc(eh->epool);
 
-       if (v1<v0) {
-               v0 ^= v1;
-               v1 ^= v0;
-               v0 ^= v1;
-       }
-       hash = EDGEHASH(v0,v1)%eh->nbuckets;
+       EDGE_ORD(v0, v1); /* ensure v0 is smaller */
+
+       hash = EDGE_HASH(v0, v1) % eh->nbuckets;
 
        e->v0 = v0;
        e->v1 = v1;
        e->val = val;
-       e->next= eh->buckets[hash];
+       e->next = eh->buckets[hash];
        eh->buckets[hash]= e;
 
-       if (++eh->nentries>eh->nbuckets*3) {
-               EdgeEntry *e, **old= eh->buckets;
-               int i, nold= eh->nbuckets;
+       if (++eh->nentries>eh->nbuckets * 3) {
+               EdgeEntry *e, **old = eh->buckets;
+               int i, nold = eh->nbuckets;
 
-               eh->nbuckets= _ehash_hashsizes[++eh->cursize];
-               eh->buckets= MEM_mallocN(eh->nbuckets*sizeof(*eh->buckets), "eh buckets");
+               eh->nbuckets = _ehash_hashsizes[++eh->cursize];
+               eh->buckets = MEM_mallocN(eh->nbuckets * sizeof(*eh->buckets), "eh buckets");
                memset(eh->buckets, 0, eh->nbuckets * sizeof(*eh->buckets));
 
-               for (i=0; i<nold; i++) {
-                       for (e= old[i]; e;) {
-                               EdgeEntry *n= e->next;
+               for (i = 0; i < nold; i++) {
+                       for (e = old[i]; e;) {
+                               EdgeEntry *n = e->next;
 
-                               hash= EDGEHASH(e->v0,e->v1)%eh->nbuckets;
-                               e->next= eh->buckets[hash];
+                               hash = EDGE_HASH(e->v0, e->v1) % eh->nbuckets;
+                               e->next = eh->buckets[hash];
                                eh->buckets[hash]= e;
 
-                               e= n;
+                               e = n;
                        }
                }
 
@@ -122,33 +128,31 @@ void BLI_edgehash_insert(EdgeHash *eh, int v0, int v1, void *val) {
        }
 }
 
-void** BLI_edgehash_lookup_p(EdgeHash *eh, int v0, int v1) {
+void **BLI_edgehash_lookup_p(EdgeHash *eh, unsigned int v0, unsigned int v1)
+{
        unsigned int hash;
        EdgeEntry *e;
 
-       if (v1<v0) {
-               v0 ^= v1;
-               v1 ^= v0;
-               v0 ^= v1;
-       }
-       hash = EDGEHASH(v0,v1)%eh->nbuckets;
-       for (e= eh->buckets[hash]; e; e= e->next)
-               if (v0==e->v0 && v1==e->v1)
+       EDGE_ORD(v0, v1); /* ensure v0 is smaller */
+
+       hash = EDGE_HASH(v0, v1) % eh->nbuckets;
+       for (e = eh->buckets[hash]; e; e = e->next)
+               if (v0 == e->v0 && v1 == e->v1)
                        return &e->val;
 
        return NULL;
 }
 
-void* BLI_edgehash_lookup(EdgeHash *eh, int v0, int v1)
+void *BLI_edgehash_lookup(EdgeHash *eh, unsigned int v0, unsigned int v1)
 {
-       void **value_p = BLI_edgehash_lookup_p(eh,v0,v1);
+       void **value_p = BLI_edgehash_lookup_p(eh, v0, v1);
 
        return value_p?*value_p:NULL;
 }
 
-int BLI_edgehash_haskey(EdgeHash *eh, int v0, int v1)
+int BLI_edgehash_haskey(EdgeHash *eh, unsigned int v0, unsigned int v1)
 {
-       return BLI_edgehash_lookup_p(eh, v0, v1)!=NULL;
+       return BLI_edgehash_lookup_p(eh, v0, v1) != NULL;
 }
 
 int BLI_edgehash_size(EdgeHash *eh)
@@ -160,21 +164,21 @@ void BLI_edgehash_clear(EdgeHash *eh, EdgeHashFreeFP valfreefp)
 {
        int i;
        
-       for (i=0; i<eh->nbuckets; i++) {
+       for (i = 0; i<eh->nbuckets; i++) {
                EdgeEntry *e;
                
-               for (e= eh->buckets[i]; e; ) {
-                       EdgeEntry *n= e->next;
+               for (e = eh->buckets[i]; e; ) {
+                       EdgeEntry *n = e->next;
                        
                        if (valfreefp) valfreefp(e->val);
                        BLI_mempool_free(eh->epool, e);
                        
-                       e= n;
+                       e = n;
                }
-               eh->buckets[i]= NULL;
+               eh->buckets[i] = NULL;
        }
 
-       eh->nentries= 0;
+       eh->nentries = 0;
 }
 
 void BLI_edgehash_free(EdgeHash *eh, EdgeHashFreeFP valfreefp)
@@ -198,15 +202,15 @@ struct EdgeHashIterator {
 
 EdgeHashIterator *BLI_edgehashIterator_new(EdgeHash *eh)
 {
-       EdgeHashIterator *ehi= MEM_mallocN(sizeof(*ehi), "eh iter");
-       ehi->eh= eh;
-       ehi->curEntry= NULL;
-       ehi->curBucket= -1;
+       EdgeHashIterator *ehi = MEM_mallocN(sizeof(*ehi), "eh iter");
+       ehi->eh = eh;
+       ehi->curEntry = NULL;
+       ehi->curBucket = -1;
        while (!ehi->curEntry) {
                ehi->curBucket++;
-               if (ehi->curBucket==ehi->eh->nbuckets)
+               if (ehi->curBucket == ehi->eh->nbuckets)
                        break;
-               ehi->curEntry= ehi->eh->buckets[ehi->curBucket];
+               ehi->curEntry = ehi->eh->buckets[ehi->curBucket];
        }
        return ehi;
 }
@@ -215,7 +219,7 @@ void BLI_edgehashIterator_free(EdgeHashIterator *ehi)
        MEM_freeN(ehi);
 }
 
-void BLI_edgehashIterator_getKey(EdgeHashIterator *ehi, int *v0_r, int *v1_r)
+void BLI_edgehashIterator_getKey(EdgeHashIterator *ehi, unsigned int *v0_r, unsigned int *v1_r)
 {
        if (ehi->curEntry) {
                *v0_r = ehi->curEntry->v0;
@@ -229,19 +233,22 @@ void *BLI_edgehashIterator_getValue(EdgeHashIterator *ehi)
 
 void BLI_edgehashIterator_setValue(EdgeHashIterator *ehi, void *val)
 {
-       if(ehi->curEntry)
-               ehi->curEntry->val= val;
+       if (ehi->curEntry) {
+               ehi->curEntry->val = val;
+       }
 }
 
 void BLI_edgehashIterator_step(EdgeHashIterator *ehi)
 {
        if (ehi->curEntry) {
-               ehi->curEntry= ehi->curEntry->next;
+               ehi->curEntry = ehi->curEntry->next;
                while (!ehi->curEntry) {
                        ehi->curBucket++;
-                       if (ehi->curBucket==ehi->eh->nbuckets)
+                       if (ehi->curBucket == ehi->eh->nbuckets) {
                                break;
-                       ehi->curEntry= ehi->eh->buckets[ehi->curBucket];
+                       }
+
+                       ehi->curEntry = ehi->eh->buckets[ehi->curBucket];
                }
        }
 }
index 52e2eec16394053d64cabdde797e653cee5d2af8..5fa49e234e7af8da27740ad61cd9f4eb65edbe0d 100644 (file)
@@ -97,7 +97,7 @@ static void dm_calc_normal(DerivedMesh *dm, float (*temp_nors)[3])
                EdgeHash *edge_hash = BLI_edgehash_new();
                EdgeHashIterator *edge_iter;
                int edge_ref_count = 0;
-               int ed_v1, ed_v2; /* use when getting the key */
+               unsigned int ed_v1, ed_v2; /* use when getting the key */
                EdgeFaceRef *edge_ref_array = MEM_callocN(numEdges * sizeof(EdgeFaceRef), "Edge Connectivity");
                EdgeFaceRef *edge_ref;
                float edge_normal[3];
@@ -105,17 +105,17 @@ static void dm_calc_normal(DerivedMesh *dm, float (*temp_nors)[3])
                /* This function adds an edge hash if its not there, and adds the face index */
 #define NOCALC_EDGEWEIGHT_ADD_EDGEREF_FACE(EDV1, EDV2); \
                        { \
-                               const unsigned int ed_v1 = EDV1; \
-                               const unsigned int ed_v2 = EDV2; \
-                               edge_ref = (EdgeFaceRef *)BLI_edgehash_lookup(edge_hash, ed_v1, ed_v2); \
+                               const unsigned int ml_v1 = EDV1; \
+                               const unsigned int ml_v2 = EDV2; \
+                               edge_ref = (EdgeFaceRef *)BLI_edgehash_lookup(edge_hash, ml_v1, ml_v2); \
                                if (!edge_ref) { \
                                        edge_ref = &edge_ref_array[edge_ref_count]; edge_ref_count++; \
                                        edge_ref->f1 = i; \
                                        edge_ref->f2 =- 1; \
-                                       BLI_edgehash_insert(edge_hash, ed_v1, ed_v2, edge_ref); \
+                                       BLI_edgehash_insert(edge_hash, ml_v1, ml_v2, edge_ref); \
                                } \
                                else { \
-                                       edge_ref->f2=i; \
+                                       edge_ref->f2 = i; \
                                } \
                        }
                /* --- end define --- */
@@ -135,7 +135,7 @@ static void dm_calc_normal(DerivedMesh *dm, float (*temp_nors)[3])
 
                for(edge_iter = BLI_edgehashIterator_new(edge_hash); !BLI_edgehashIterator_isDone(edge_iter); BLI_edgehashIterator_step(edge_iter)) {
                        /* Get the edge vert indices, and edge value (the face indices that use it)*/
-                       BLI_edgehashIterator_getKey(edge_iter, (int*)&ed_v1, (int*)&ed_v2);
+                       BLI_edgehashIterator_getKey(edge_iter, &ed_v1, &ed_v2);
                        edge_ref = BLI_edgehashIterator_getValue(edge_iter);
 
                        if (edge_ref->f2 != -1) {
@@ -264,7 +264,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
        if(smd->flag & MOD_SOLIDIFY_RIM) {
                EdgeHash *edgehash = BLI_edgehash_new();
                EdgeHashIterator *ehi;
-               int v1, v2;
+               unsigned int v1, v2;
                int eidx;
 
                for(i=0, mv=orig_mvert; i<numVerts; i++, mv++) {