[Bf-blender-cvs] [25c9ea8] master: GHash, EdgeHash: hint on unlikely branch
Campbell Barton
noreply at git.blender.org
Sun Apr 20 18:53:47 CEST 2014
Commit: 25c9ea8cb3215408d6c3de7b06a5fe4b07e4b435
Author: Campbell Barton
Date: Mon Apr 21 02:50:07 2014 +1000
https://developer.blender.org/rB25c9ea8cb3215408d6c3de7b06a5fe4b07e4b435
GHash, EdgeHash: hint on unlikely branch
also avoid searching buckets for empty hashes
===================================================================
M source/blender/blenlib/intern/BLI_ghash.c
M source/blender/blenlib/intern/edgehash.c
===================================================================
diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c
index 4849ef3..1df4888 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 40b484e..8558e57 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];
- }
- }
-}
-
/** \} */
/* -------------------------------------------------------------------- */
More information about the Bf-blender-cvs
mailing list