diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-06-23 02:30:56 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-06-23 02:30:56 +0400 |
commit | 1a50be2d94dc5bc6e87e6669b79d66c3771585a2 (patch) | |
tree | 640e3818a9d1459ef339e32d0b60865c57ad7a54 | |
parent | 1fb980e7df3587982e9117c409f4c1e5af50c90a (diff) |
Make edgehash and ghash use the same limit for expanding buckets, r26206 changed ghash.
double checked and r26206 does indeed give a speedup, so change for edgehash too.
-rw-r--r-- | source/blender/blenlib/intern/BLI_ghash.c | 15 | ||||
-rw-r--r-- | source/blender/blenlib/intern/edgehash.c | 20 |
2 files changed, 18 insertions, 17 deletions
diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c index 78b91c7ef5a..d30d3f3d256 100644 --- a/source/blender/blenlib/intern/BLI_ghash.c +++ b/source/blender/blenlib/intern/BLI_ghash.c @@ -28,6 +28,8 @@ /** \file blender/blenlib/intern/BLI_ghash.c * \ingroup bli + * + * \note edgehash.c is based on this, make sure they stay in sync. */ #include <string.h> @@ -90,22 +92,21 @@ void BLI_ghash_insert(GHash *gh, void *key, void *val) e->val = val; gh->buckets[hash] = e; - if (++gh->nentries > (float)gh->nbuckets / 2) { + if (UNLIKELY(++gh->nentries > gh->nbuckets / 2)) { Entry **old = gh->buckets; - unsigned int i, nold = gh->nbuckets; + const unsigned nold = gh->nbuckets; + unsigned int i; gh->nbuckets = hashsizes[++gh->cursize]; gh->buckets = (Entry **)MEM_callocN(gh->nbuckets * sizeof(*gh->buckets), "buckets"); for (i = 0; i < nold; i++) { - for (e = old[i]; e; ) { - Entry *n = e->next; - + Entry *e_next; + for (e = old[i]; e; e = e_next) { + e_next = e->next; hash = gh->hashfp(e->key) % gh->nbuckets; e->next = gh->buckets[hash]; gh->buckets[hash] = e; - - e = n; } } diff --git a/source/blender/blenlib/intern/edgehash.c b/source/blender/blenlib/intern/edgehash.c index 68eab5f60e7..6ed9b559711 100644 --- a/source/blender/blenlib/intern/edgehash.c +++ b/source/blender/blenlib/intern/edgehash.c @@ -28,6 +28,8 @@ /** \file blender/blenlib/intern/edgehash.c * \ingroup bli + * + * \note Based on 'BLI_ghash.c', make sure these stay in sync. */ @@ -110,29 +112,27 @@ void BLI_edgehash_insert(EdgeHash *eh, unsigned int v0, unsigned int v1, void *v hash = EDGE_HASH(v0, v1) % eh->nbuckets; + e->next = eh->buckets[hash]; e->v0 = v0; e->v1 = v1; e->val = val; - e->next = eh->buckets[hash]; eh->buckets[hash] = e; - if (++eh->nentries > eh->nbuckets * 3) { + if (UNLIKELY(++eh->nentries > eh->nbuckets / 2)) { EdgeEntry **old = eh->buckets; - unsigned int i, nold = eh->nbuckets; + const unsigned int nold = eh->nbuckets; + unsigned int i; 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)); + eh->buckets = MEM_callocN(eh->nbuckets * sizeof(*eh->buckets), "eh buckets"); for (i = 0; i < nold; i++) { - for (e = old[i]; e; ) { - EdgeEntry *n = e->next; - + EdgeEntry *e_next; + for (e = old[i]; e; e = e_next) { + e_next = e->next; hash = EDGE_HASH(e->v0, e->v1) % eh->nbuckets; e->next = eh->buckets[hash]; eh->buckets[hash] = e; - - e = n; } } |