diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-04-20 20:50:07 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-04-20 20:50:07 +0400 |
commit | 25c9ea8cb3215408d6c3de7b06a5fe4b07e4b435 (patch) | |
tree | ebb6a16709a2a9212cae9a6715db11ab1db5fc6c /source/blender | |
parent | 3ba7a75a6c317cee35a96594ea050f23ad136a44 (diff) |
GHash, EdgeHash: hint on unlikely branch
also avoid searching buckets for empty hashes
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenlib/intern/BLI_ghash.c | 48 | ||||
-rw-r--r-- | source/blender/blenlib/intern/edgehash.c | 50 |
2 files changed, 52 insertions, 46 deletions
diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c index 4849ef3e958..1df48885637 100644 --- a/source/blender/blenlib/intern/BLI_ghash.c +++ b/source/blender/blenlib/intern/BLI_ghash.c @@ -559,11 +559,31 @@ void BLI_ghashIterator_init(GHashIterator *ghi, GHash *gh) ghi->gh = gh; ghi->curEntry = NULL; ghi->curBucket = UINT_MAX; /* wraps to zero */ - while (!ghi->curEntry) { - ghi->curBucket++; - if (ghi->curBucket == ghi->gh->nbuckets) - break; - ghi->curEntry = ghi->gh->buckets[ghi->curBucket]; + if (gh->nentries) { + while (!ghi->curEntry) { + ghi->curBucket++; + if (UNLIKELY(ghi->curBucket == ghi->gh->nbuckets)) + break; + ghi->curEntry = ghi->gh->buckets[ghi->curBucket]; + } + } +} + +/** + * Steps the iterator to the next index. + * + * \param ghi The iterator. + */ +void BLI_ghashIterator_step(GHashIterator *ghi) +{ + if (ghi->curEntry) { + ghi->curEntry = ghi->curEntry->next; + while (!ghi->curEntry) { + ghi->curBucket++; + if (ghi->curBucket == ghi->gh->nbuckets) + break; + ghi->curEntry = ghi->gh->buckets[ghi->curBucket]; + } } } @@ -628,24 +648,6 @@ bool BLI_ghashIterator_done(GHashIterator *ghi) } #endif -/** - * Steps the iterator to the next index. - * - * \param ghi The iterator. - */ -void BLI_ghashIterator_step(GHashIterator *ghi) -{ - if (ghi->curEntry) { - ghi->curEntry = ghi->curEntry->next; - while (!ghi->curEntry) { - ghi->curBucket++; - if (ghi->curBucket == ghi->gh->nbuckets) - break; - ghi->curEntry = ghi->gh->buckets[ghi->curBucket]; - } - } -} - /** \} */ diff --git a/source/blender/blenlib/intern/edgehash.c b/source/blender/blenlib/intern/edgehash.c index 40b484e1974..8558e5773c7 100644 --- a/source/blender/blenlib/intern/edgehash.c +++ b/source/blender/blenlib/intern/edgehash.c @@ -452,11 +452,33 @@ void BLI_edgehashIterator_init(EdgeHashIterator *ehi, EdgeHash *eh) ehi->eh = eh; ehi->curEntry = NULL; ehi->curBucket = UINT_MAX; /* wraps to zero */ - while (!ehi->curEntry) { - ehi->curBucket++; - if (ehi->curBucket == ehi->eh->nbuckets) - break; - ehi->curEntry = ehi->eh->buckets[ehi->curBucket]; + if (eh->nentries) { + while (!ehi->curEntry) { + ehi->curBucket++; + if (UNLIKELY(ehi->curBucket == ehi->eh->nbuckets)) { + break; + } + + ehi->curEntry = ehi->eh->buckets[ehi->curBucket]; + } + } +} + +/** + * Steps the iterator to the next index. + */ +void BLI_edgehashIterator_step(EdgeHashIterator *ehi) +{ + if (ehi->curEntry) { + ehi->curEntry = ehi->curEntry->next; + while (!ehi->curEntry) { + ehi->curBucket++; + if (UNLIKELY(ehi->curBucket == ehi->eh->nbuckets)) { + break; + } + + ehi->curEntry = ehi->eh->buckets[ehi->curBucket]; + } } } @@ -512,24 +534,6 @@ bool BLI_edgehashIterator_isDone(EdgeHashIterator *ehi) } #endif -/** - * Steps the iterator to the next index. - */ -void BLI_edgehashIterator_step(EdgeHashIterator *ehi) -{ - if (ehi->curEntry) { - ehi->curEntry = ehi->curEntry->next; - while (!ehi->curEntry) { - ehi->curBucket++; - if (ehi->curBucket == ehi->eh->nbuckets) { - break; - } - - ehi->curEntry = ehi->eh->buckets[ehi->curBucket]; - } - } -} - /** \} */ /* -------------------------------------------------------------------- */ |