Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2014-04-08 09:50:38 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-04-08 09:50:38 +0400
commit5580afb5dfe98771c7db8b0660398c47751c1ade (patch)
treef99c7913a62f561a29dd6abc918868232275ce24 /source/blender
parentebaf3781fa4165808cd9ddb2ed0944788a31af7c (diff)
GHash/Edgehash: make simple iterator checking functions inline.
also remove NULL check, only a few areas made use of this.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenlib/BLI_edgehash.h34
-rw-r--r--source/blender/blenlib/BLI_ghash.h23
-rw-r--r--source/blender/blenlib/intern/BLI_ghash.c33
-rw-r--r--source/blender/blenlib/intern/edgehash.c55
-rw-r--r--source/blender/bmesh/intern/bmesh_operators.c34
-rw-r--r--source/blender/bmesh/operators/bmo_hull.c4
6 files changed, 113 insertions, 70 deletions
diff --git a/source/blender/blenlib/BLI_edgehash.h b/source/blender/blenlib/BLI_edgehash.h
index fccbda4b4db..b4ca25bed4f 100644
--- a/source/blender/blenlib/BLI_edgehash.h
+++ b/source/blender/blenlib/BLI_edgehash.h
@@ -32,9 +32,13 @@
#include "BLI_compiler_attrs.h"
struct EdgeHash;
-struct EdgeHashIterator;
typedef struct EdgeHash EdgeHash;
-typedef struct EdgeHashIterator EdgeHashIterator;
+
+typedef struct EdgeHashIterator {
+ EdgeHash *eh;
+ struct EdgeEntry *curEntry;
+ unsigned int curBucket;
+} EdgeHashIterator;
typedef void (*EdgeHashFreeFP)(void *key);
@@ -59,13 +63,29 @@ void BLI_edgehash_flag_set(EdgeHash *eh, unsigned int flag);
void BLI_edgehash_flag_clear(EdgeHash *eh, unsigned int flag);
EdgeHashIterator *BLI_edgehashIterator_new(EdgeHash *eh) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT;
+void BLI_edgehashIterator_init(EdgeHashIterator *ehi, EdgeHash *eh);
void BLI_edgehashIterator_free(EdgeHashIterator *ehi);
-void BLI_edgehashIterator_getKey(EdgeHashIterator *ehi, unsigned int *r_v0, unsigned int *r_v1);
-void *BLI_edgehashIterator_getValue(EdgeHashIterator *ehi) ATTR_WARN_UNUSED_RESULT;
-void **BLI_edgehashIterator_getValue_p(EdgeHashIterator *ehi) ATTR_WARN_UNUSED_RESULT;
-void BLI_edgehashIterator_setValue(EdgeHashIterator *ehi, void *val);
void BLI_edgehashIterator_step(EdgeHashIterator *ehi);
-bool BLI_edgehashIterator_isDone(EdgeHashIterator *ehi) ATTR_WARN_UNUSED_RESULT;
+
+BLI_INLINE bool BLI_edgehashIterator_isDone(EdgeHashIterator *ehi) ATTR_WARN_UNUSED_RESULT;
+BLI_INLINE void BLI_edgehashIterator_getKey(EdgeHashIterator *ehi, unsigned int *r_v0, unsigned int *r_v1);
+BLI_INLINE void *BLI_edgehashIterator_getValue(EdgeHashIterator *ehi) ATTR_WARN_UNUSED_RESULT;
+BLI_INLINE void **BLI_edgehashIterator_getValue_p(EdgeHashIterator *ehi) ATTR_WARN_UNUSED_RESULT;
+BLI_INLINE void BLI_edgehashIterator_setValue(EdgeHashIterator *ehi, void *val);
+
+struct _eh_Entry { void *next; unsigned int v0, v1; void *val; };
+BLI_INLINE void BLI_edgehashIterator_getKey(EdgeHashIterator *ehi, unsigned int *r_v0, unsigned int *r_v1)
+{ *r_v0 = ((struct _eh_Entry *)ehi->curEntry)->v0; *r_v1 = ((struct _eh_Entry *)ehi->curEntry)->v1; }
+BLI_INLINE void *BLI_edgehashIterator_getValue(EdgeHashIterator *ehi) { return ((struct _eh_Entry *)ehi->curEntry)->val; }
+BLI_INLINE void **BLI_edgehashIterator_getValue_p(EdgeHashIterator *ehi) { return &((struct _eh_Entry *)ehi->curEntry)->val; }
+BLI_INLINE void BLI_edgehashIterator_setValue(EdgeHashIterator *ehi, void *val) { ((struct _eh_Entry *)ehi->curEntry)->val = val; }
+BLI_INLINE bool BLI_edgehashIterator_isDone(EdgeHashIterator *ehi) { return (((struct _eh_Entry *)ehi->curEntry) == NULL); }
+/* disallow further access */
+#ifdef __GNUC__
+# pragma GCC poison _eh_Entry
+#else
+# define _eh_Entry void
+#endif
#define BLI_EDGEHASH_SIZE_GUESS_FROM_LOOPS(totloop) ((totloop) / 2)
#define BLI_EDGEHASH_SIZE_GUESS_FROM_POLYS(totpoly) ((totpoly) * 2)
diff --git a/source/blender/blenlib/BLI_ghash.h b/source/blender/blenlib/BLI_ghash.h
index e5a93691ad0..61a75ebb7e8 100644
--- a/source/blender/blenlib/BLI_ghash.h
+++ b/source/blender/blenlib/BLI_ghash.h
@@ -83,13 +83,24 @@ GHashIterator *BLI_ghashIterator_new(GHash *gh) ATTR_MALLOC ATTR_WARN_UNUSED_RES
void BLI_ghashIterator_init(GHashIterator *ghi, GHash *gh);
void BLI_ghashIterator_free(GHashIterator *ghi);
-
-void *BLI_ghashIterator_getKey(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT;
-void *BLI_ghashIterator_getValue(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT;
-void **BLI_ghashIterator_getValue_p(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT;
-
void BLI_ghashIterator_step(GHashIterator *ghi);
-bool BLI_ghashIterator_done(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT;
+
+BLI_INLINE void *BLI_ghashIterator_getKey(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT;
+BLI_INLINE void *BLI_ghashIterator_getValue(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT;
+BLI_INLINE void **BLI_ghashIterator_getValue_p(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT;
+BLI_INLINE bool BLI_ghashIterator_done(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT;
+
+struct _gh_Entry { void *next, *key, *val; };
+BLI_INLINE void *BLI_ghashIterator_getKey(GHashIterator *ghi) { return ((struct _gh_Entry *)ghi->curEntry)->key; }
+BLI_INLINE void *BLI_ghashIterator_getValue(GHashIterator *ghi) { return ((struct _gh_Entry *)ghi->curEntry)->val; }
+BLI_INLINE void **BLI_ghashIterator_getValue_p(GHashIterator *ghi) { return &((struct _gh_Entry *)ghi->curEntry)->val; }
+BLI_INLINE bool BLI_ghashIterator_done(GHashIterator *ghi) { return !ghi->curEntry; }
+/* disallow further access */
+#ifdef __GNUC__
+# pragma GCC poison _gh_Entry
+#else
+# define _gh_Entry void
+#endif
#define GHASH_ITER(gh_iter_, ghash_) \
for (BLI_ghashIterator_init(&gh_iter_, ghash_); \
diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c
index 169b98da267..e30883611a8 100644
--- a/source/blender/blenlib/intern/BLI_ghash.c
+++ b/source/blender/blenlib/intern/BLI_ghash.c
@@ -577,6 +577,8 @@ void BLI_ghashIterator_free(GHashIterator *ghi)
MEM_freeN(ghi);
}
+/* inline functions now */
+#if 0
/**
* Retrieve the key from an iterator.
*
@@ -586,7 +588,7 @@ void BLI_ghashIterator_free(GHashIterator *ghi)
*/
void *BLI_ghashIterator_getKey(GHashIterator *ghi)
{
- return ghi->curEntry ? ghi->curEntry->key : NULL;
+ return ghi->curEntry->key;
}
/**
@@ -598,7 +600,7 @@ void *BLI_ghashIterator_getKey(GHashIterator *ghi)
*/
void *BLI_ghashIterator_getValue(GHashIterator *ghi)
{
- return ghi->curEntry ? ghi->curEntry->val : NULL;
+ return ghi->curEntry->val;
}
/**
@@ -610,8 +612,21 @@ void *BLI_ghashIterator_getValue(GHashIterator *ghi)
*/
void **BLI_ghashIterator_getValue_p(GHashIterator *ghi)
{
- return ghi->curEntry ? &ghi->curEntry->val : NULL;
+ return &ghi->curEntry->val;
+}
+
+/**
+ * Determine if an iterator is done (has reached the end of
+ * the hash table).
+ *
+ * \param ghi The iterator.
+ * \return True if done, False otherwise.
+ */
+bool BLI_ghashIterator_done(GHashIterator *ghi)
+{
+ return ghi->curEntry == NULL;
}
+#endif
/**
* Steps the iterator to the next index.
@@ -631,18 +646,6 @@ void BLI_ghashIterator_step(GHashIterator *ghi)
}
}
-/**
- * Determine if an iterator is done (has reached the end of
- * the hash table).
- *
- * \param ghi The iterator.
- * \return True if done, False otherwise.
- */
-bool BLI_ghashIterator_done(GHashIterator *ghi)
-{
- return ghi->curEntry == NULL;
-}
-
/** \} */
diff --git a/source/blender/blenlib/intern/edgehash.c b/source/blender/blenlib/intern/edgehash.c
index 1d0e62dfdf6..40b484e1974 100644
--- a/source/blender/blenlib/intern/edgehash.c
+++ b/source/blender/blenlib/intern/edgehash.c
@@ -427,13 +427,6 @@ void BLI_edgehash_flag_clear(EdgeHash *eh, unsigned int flag)
/** \name Iterator API
* \{ */
-struct EdgeHashIterator {
- EdgeHash *eh;
- unsigned int curBucket;
- EdgeEntry *curEntry;
-};
-
-
/**
* Create a new EdgeHashIterator. The hash table must not be mutated
* while the iterator is in use, and the iterator will step exactly
@@ -442,6 +435,20 @@ struct EdgeHashIterator {
EdgeHashIterator *BLI_edgehashIterator_new(EdgeHash *eh)
{
EdgeHashIterator *ehi = MEM_mallocN(sizeof(*ehi), "eh iter");
+ BLI_edgehashIterator_init(ehi, eh);
+ return ehi;
+}
+
+/**
+ * Init an already allocated EdgeHashIterator. The hash table must not
+ * be mutated while the iterator is in use, and the iterator will
+ * step exactly BLI_edgehash_size(eh) times before becoming done.
+ *
+ * \param ehi The EdgeHashIterator to initialize.
+ * \param eh The EdgeHash to iterate over.
+ */
+void BLI_edgehashIterator_init(EdgeHashIterator *ehi, EdgeHash *eh)
+{
ehi->eh = eh;
ehi->curEntry = NULL;
ehi->curBucket = UINT_MAX; /* wraps to zero */
@@ -451,7 +458,6 @@ EdgeHashIterator *BLI_edgehashIterator_new(EdgeHash *eh)
break;
ehi->curEntry = ehi->eh->buckets[ehi->curBucket];
}
- return ehi;
}
/**
@@ -462,15 +468,15 @@ void BLI_edgehashIterator_free(EdgeHashIterator *ehi)
MEM_freeN(ehi);
}
+/* inline functions now */
+#if 0
/**
* Retrieve the key from an iterator.
*/
void BLI_edgehashIterator_getKey(EdgeHashIterator *ehi, unsigned int *r_v0, unsigned int *r_v1)
{
- if (ehi->curEntry) {
- *r_v0 = ehi->curEntry->v0;
- *r_v1 = ehi->curEntry->v1;
- }
+ *r_v0 = ehi->curEntry->v0;
+ *r_v1 = ehi->curEntry->v1;
}
/**
@@ -478,7 +484,7 @@ void BLI_edgehashIterator_getKey(EdgeHashIterator *ehi, unsigned int *r_v0, unsi
*/
void *BLI_edgehashIterator_getValue(EdgeHashIterator *ehi)
{
- return ehi->curEntry ? ehi->curEntry->val : NULL;
+ return ehi->curEntry->val;
}
/**
@@ -486,7 +492,7 @@ void *BLI_edgehashIterator_getValue(EdgeHashIterator *ehi)
*/
void **BLI_edgehashIterator_getValue_p(EdgeHashIterator *ehi)
{
- return ehi->curEntry ? &ehi->curEntry->val : NULL;
+ return &ehi->curEntry->val;
}
/**
@@ -494,10 +500,17 @@ void **BLI_edgehashIterator_getValue_p(EdgeHashIterator *ehi)
*/
void BLI_edgehashIterator_setValue(EdgeHashIterator *ehi, void *val)
{
- if (ehi->curEntry) {
- ehi->curEntry->val = val;
- }
+ ehi->curEntry->val = val;
+}
+
+/**
+ * Determine if an iterator is done.
+ */
+bool BLI_edgehashIterator_isDone(EdgeHashIterator *ehi)
+{
+ return (ehi->curEntry == NULL);
}
+#endif
/**
* Steps the iterator to the next index.
@@ -517,14 +530,6 @@ void BLI_edgehashIterator_step(EdgeHashIterator *ehi)
}
}
-/**
- * Determine if an iterator is done.
- */
-bool BLI_edgehashIterator_isDone(EdgeHashIterator *ehi)
-{
- return (ehi->curEntry == NULL);
-}
-
/** \} */
/* -------------------------------------------------------------------- */
diff --git a/source/blender/bmesh/intern/bmesh_operators.c b/source/blender/bmesh/intern/bmesh_operators.c
index 086233ebe09..2a6b4d70419 100644
--- a/source/blender/bmesh/intern/bmesh_operators.c
+++ b/source/blender/bmesh/intern/bmesh_operators.c
@@ -347,13 +347,10 @@ void _bmo_slot_copy(BMOpSlot slot_args_src[BMO_OP_MAX_SLOTS], const char *slot_n
}
}
else if (slot_dst->slot_type == BMO_OP_SLOT_MAPPING) {
- GHashIterator it;
- for (BLI_ghashIterator_init(&it, slot_src->data.ghash);
- BLI_ghashIterator_done(&it) == false;
- BLI_ghashIterator_step(&it))
- {
- void *key = BLI_ghashIterator_getKey(&it);
- void *val = BLI_ghashIterator_getValue(&it);
+ GHashIterator gh_iter;
+ GHASH_ITER (gh_iter, slot_src->data.ghash) {
+ void *key = BLI_ghashIterator_getKey(&gh_iter);
+ void *val = BLI_ghashIterator_getValue(&gh_iter);
BLI_ghash_insert(slot_dst->data.ghash, key, val);
}
}
@@ -722,17 +719,15 @@ void *bmo_slot_buffer_grow(BMesh *bm, BMOperator *op, int slot_code, int totadd)
void BMO_slot_map_to_flag(BMesh *bm, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name,
const char htype, const short oflag)
{
- GHashIterator it;
+ GHashIterator gh_iter;
BMOpSlot *slot = BMO_slot_get(slot_args, slot_name);
BMElemF *ele_f;
BLI_assert(slot->slot_type == BMO_OP_SLOT_MAPPING);
- for (BLI_ghashIterator_init(&it, slot->data.ghash);
- (ele_f = BLI_ghashIterator_getKey(&it));
- BLI_ghashIterator_step(&it))
- {
+ GHASH_ITER (gh_iter, slot->data.ghash) {
+ ele_f = BLI_ghashIterator_getKey(&gh_iter);
if (ele_f->head.htype & htype) {
BMO_elem_flag_enable(bm, ele_f, oflag);
}
@@ -1424,10 +1419,19 @@ void *BMO_iter_step(BMOIter *iter)
return ele;
}
else if (slot->slot_type == BMO_OP_SLOT_MAPPING) {
- void *ret = BLI_ghashIterator_getKey(&iter->giter);
- iter->val = BLI_ghashIterator_getValue_p(&iter->giter);
+ void *ret;
+
+
+ if (BLI_ghashIterator_done(&iter->giter) == false) {
+ ret = BLI_ghashIterator_getKey(&iter->giter);
+ iter->val = BLI_ghashIterator_getValue_p(&iter->giter);
- BLI_ghashIterator_step(&iter->giter);
+ BLI_ghashIterator_step(&iter->giter);
+ }
+ else {
+ ret = NULL;
+ iter->val = NULL;
+ }
return ret;
}
diff --git a/source/blender/bmesh/operators/bmo_hull.c b/source/blender/bmesh/operators/bmo_hull.c
index 1082955b466..26a4dbe1e1d 100644
--- a/source/blender/bmesh/operators/bmo_hull.c
+++ b/source/blender/bmesh/operators/bmo_hull.c
@@ -217,11 +217,11 @@ static HullFinalEdges *hull_final_edges(GSet *hull_triangles)
final_edges->link_pool = BLI_mempool_create(sizeof(LinkData), 0, 128, BLI_MEMPOOL_NOP);
GSET_ITER (iter, hull_triangles) {
+ HullTriangle *t = BLI_gsetIterator_getKey(&iter);
LinkData *link;
int i;
-
+
for (i = 0; i < 3; i++) {
- HullTriangle *t = BLI_gsetIterator_getKey(&iter);
BMVert *v1 = t->v[i];
BMVert *v2 = t->v[(i + 1) % 3];
ListBase *adj;