[Bf-blender-cvs] [5580afb] master: GHash/Edgehash: make simple iterator checking functions inline.

Campbell Barton noreply at git.blender.org
Tue Apr 8 07:56:05 CEST 2014


Commit: 5580afb5dfe98771c7db8b0660398c47751c1ade
Author: Campbell Barton
Date:   Tue Apr 8 15:50:38 2014 +1000
https://developer.blender.org/rB5580afb5dfe98771c7db8b0660398c47751c1ade

GHash/Edgehash: make simple iterator checking functions inline.

also remove NULL check, only a few areas made use of this.

===================================================================

M	source/blender/blenlib/BLI_edgehash.h
M	source/blender/blenlib/BLI_ghash.h
M	source/blender/blenlib/intern/BLI_ghash.c
M	source/blender/blenlib/intern/edgehash.c
M	source/blender/bmesh/intern/bmesh_operators.c
M	source/blender/bmesh/operators/bmo_hull.c

===================================================================

diff --git a/source/blender/blenlib/BLI_edgehash.h b/source/blender/blenlib/BLI_edgehash.h
index fccbda4..b4ca25b 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 e5a9369..61a75eb 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 169b98d..e308836 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 1d0e62d..40b484e 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 086233e..2a6b4d7 100644
--- a/source/blender/bmesh/intern/bmesh_operators.c
+++ b/source/blender/bmesh/intern/bmesh_o

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list