[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39316] trunk/blender/source/blender/ blenlib: un-inline GHash functions r26206, these are quite large functions to inline and increase binary size by 30kb , (tested on stripped, cmake release build).

Campbell Barton ideasman42 at gmail.com
Fri Aug 12 04:23:07 CEST 2011


Revision: 39316
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39316
Author:   campbellbarton
Date:     2011-08-12 02:23:06 +0000 (Fri, 12 Aug 2011)
Log Message:
-----------
un-inline GHash functions r26206, these are quite large functions to inline and increase binary size by 30kb, (tested on stripped, cmake release build).

Ran some speed tests and difference was close to the noise level, but inlining gives only ~2 - 3% speedup with build modifier which uses ghash a lot.

Revision Links:
--------------
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=26206

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_ghash.h
    trunk/blender/source/blender/blenlib/intern/BLI_ghash.c

Modified: trunk/blender/source/blender/blenlib/BLI_ghash.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_ghash.h	2011-08-12 00:06:03 UTC (rev 39315)
+++ trunk/blender/source/blender/blenlib/BLI_ghash.h	2011-08-12 02:23:06 UTC (rev 39316)
@@ -53,14 +53,14 @@
 
 typedef struct Entry {
 	struct Entry *next;
-	
+
 	void *key, *val;
 } Entry;
 
 typedef struct GHash {
 	GHashHashFP	hashfp;
 	GHashCmpFP	cmpfp;
-	
+
 	Entry **buckets;
 	struct BLI_mempool *entrypool;
 	int nbuckets, nentries, cursize;
@@ -72,16 +72,16 @@
 	struct Entry *curEntry;
 } GHashIterator;
 
-GHash*	BLI_ghash_new		(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info);
-void	BLI_ghash_free		(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp);
+/* *** */
 
-//BM_INLINE void	BLI_ghash_insert	(GHash *gh, void *key, void *val);
-//BM_INLINE int		BLI_ghash_remove	(GHash *gh, void *key, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp);
-//BM_INLINE void*	BLI_ghash_lookup	(GHash *gh, void *key);
-//BM_INLINE int		BLI_ghash_haskey	(GHash *gh, void *key);
+GHash* BLI_ghash_new   (GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info);
+void   BLI_ghash_free  (GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp);
+void   BLI_ghash_insert(GHash *gh, void *key, void *val);
+void * BLI_ghash_lookup(GHash *gh, const void *key);
+int    BLI_ghash_remove(GHash *gh, void *key, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp);
+int    BLI_ghash_haskey(GHash *gh, void *key);
+int	   BLI_ghash_size  (GHash *gh);
 
-int		BLI_ghash_size		(GHash *gh);
-
 /* *** */
 
 	/**
@@ -149,127 +149,10 @@
 int				BLI_ghashutil_strcmp	(const void *a, const void *b);
 
 unsigned int	BLI_ghashutil_inthash	(const void *ptr);
-int				BLI_ghashutil_intcmp(const void *a, const void *b);
+int				BLI_ghashutil_intcmp	(const void *a, const void *b);
 
-/*begin of macro-inlined functions*/
-extern unsigned int hashsizes[];
-
-#if 0
-#define BLI_ghash_insert(gh, _k, _v){\
-	unsigned int _hash= (gh)->hashfp(_k)%gh->nbuckets;\
-	Entry *_e= BLI_mempool_alloc((gh)->entrypool);\
-	_e->key= _k;\
-	_e->val= _v;\
-	_e->next= (gh)->buckets[_hash];\
-	(gh)->buckets[_hash]= _e;\
-	if (++(gh)->nentries>(gh)->nbuckets*3) {\
-		Entry *_e, **_old= (gh)->buckets;\
-		int _i, _nold= (gh)->nbuckets;\
-		(gh)->nbuckets= hashsizes[++(gh)->cursize];\
-		(gh)->buckets= malloc((gh)->nbuckets*sizeof(*(gh)->buckets));\
-		memset((gh)->buckets, 0, (gh)->nbuckets*sizeof(*(gh)->buckets));\
-		for (_i=0; _i<_nold; _i++) {\
-			for (_e= _old[_i]; _e;) {\
-				Entry *_n= _e->next;\
-				_hash= (gh)->hashfp(_e->key)%(gh)->nbuckets;\
-				_e->next= (gh)->buckets[_hash];\
-				(gh)->buckets[_hash]= _e;\
-				_e= _n;\
-			}\
-		}\
-		free(_old); } }
-#endif
-
-/*---------inlined functions---------*/
-BM_INLINE void BLI_ghash_insert(GHash *gh, void *key, void *val) {
-	unsigned int hash= gh->hashfp(key)%gh->nbuckets;
-	Entry *e= (Entry*) BLI_mempool_alloc(gh->entrypool);
-
-	e->key= key;
-	e->val= val;
-	e->next= gh->buckets[hash];
-	gh->buckets[hash]= e;
-	
-	if (++gh->nentries>(float)gh->nbuckets/2) {
-		Entry **old= gh->buckets;
-		int i, nold= gh->nbuckets;
-		
-		gh->nbuckets= hashsizes[++gh->cursize];
-		gh->buckets= (Entry**)MEM_mallocN(gh->nbuckets*sizeof(*gh->buckets), "buckets");
-		memset(gh->buckets, 0, gh->nbuckets*sizeof(*gh->buckets));
-		
-		for (i=0; i<nold; i++) {
-			for (e= old[i]; e;) {
-				Entry *n= e->next;
-				
-				hash= gh->hashfp(e->key)%gh->nbuckets;
-				e->next= gh->buckets[hash];
-				gh->buckets[hash]= e;
-				
-				e= n;
-			}
-		}
-		
-		MEM_freeN(old);
-	}
-}
-
-BM_INLINE void* BLI_ghash_lookup(GHash *gh, const void *key) 
-{
-	if(gh) {
-		unsigned int hash= gh->hashfp(key)%gh->nbuckets;
-		Entry *e;
-		
-		for (e= gh->buckets[hash]; e; e= e->next)
-			if (gh->cmpfp(key, e->key)==0)
-				return e->val;
-	}	
-	return NULL;
-}
-
-BM_INLINE int BLI_ghash_remove (GHash *gh, void *key, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
-{
-	unsigned int hash= gh->hashfp(key)%gh->nbuckets;
-	Entry *e;
-	Entry *p = NULL;
-
-	for (e= gh->buckets[hash]; e; e= e->next) {
-		if (gh->cmpfp(key, e->key)==0) {
-			Entry *n= e->next;
-
-			if (keyfreefp) keyfreefp(e->key);
-			if (valfreefp) valfreefp(e->val);
-			BLI_mempool_free(gh->entrypool, e);
-
-
-			e= n;
-			if (p)
-				p->next = n;
-			else
-				gh->buckets[hash] = n;
-
-			--gh->nentries;
-			return 1;
-		}
-		p = e;
-	}
- 
-	return 0;
-}
-
-BM_INLINE int BLI_ghash_haskey(GHash *gh, void *key) {
-	unsigned int hash= gh->hashfp(key)%gh->nbuckets;
-	Entry *e;
-	
-	for (e= gh->buckets[hash]; e; e= e->next)
-		if (gh->cmpfp(key, e->key)==0)
-			return 1;
-	
-	return 0;
-}
-
 #ifdef __cplusplus
 }
 #endif
 
-#endif
+#endif /* BLI_GHASH_H */

Modified: trunk/blender/source/blender/blenlib/intern/BLI_ghash.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/BLI_ghash.c	2011-08-12 00:06:03 UTC (rev 39315)
+++ trunk/blender/source/blender/blenlib/intern/BLI_ghash.c	2011-08-12 02:23:06 UTC (rev 39316)
@@ -49,8 +49,6 @@
 
 /***/
 
-/***/
-
 GHash *BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info) {
 	GHash *gh= MEM_mallocN(sizeof(*gh), info);
 	gh->hashfp= hashfp;
@@ -67,14 +65,96 @@
 	return gh;
 }
 
-#ifdef BLI_ghash_insert
-#undef BLI_ghash_insert
-#endif
-
 int BLI_ghash_size(GHash *gh) {
 	return gh->nentries;
 }
 
+void BLI_ghash_insert(GHash *gh, void *key, void *val) {
+	unsigned int hash= gh->hashfp(key)%gh->nbuckets;
+	Entry *e= (Entry*) BLI_mempool_alloc(gh->entrypool);
+
+	e->key= key;
+	e->val= val;
+	e->next= gh->buckets[hash];
+	gh->buckets[hash]= e;
+
+	if (++gh->nentries>(float)gh->nbuckets/2) {
+		Entry **old= gh->buckets;
+		int i, nold= gh->nbuckets;
+
+		gh->nbuckets= hashsizes[++gh->cursize];
+		gh->buckets= (Entry**)MEM_mallocN(gh->nbuckets*sizeof(*gh->buckets), "buckets");
+		memset(gh->buckets, 0, gh->nbuckets*sizeof(*gh->buckets));
+
+		for (i=0; i<nold; i++) {
+			for (e= old[i]; e;) {
+				Entry *n= e->next;
+
+				hash= gh->hashfp(e->key)%gh->nbuckets;
+				e->next= gh->buckets[hash];
+				gh->buckets[hash]= e;
+
+				e= n;
+			}
+		}
+
+		MEM_freeN(old);
+	}
+}
+
+void *BLI_ghash_lookup(GHash *gh, const void *key) {
+	if(gh) {
+		unsigned int hash= gh->hashfp(key)%gh->nbuckets;
+		Entry *e;
+
+		for (e= gh->buckets[hash]; e; e= e->next)
+			if (gh->cmpfp(key, e->key)==0)
+				return e->val;
+	}
+	return NULL;
+}
+
+int BLI_ghash_remove (GHash *gh, void *key, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
+{
+	unsigned int hash= gh->hashfp(key)%gh->nbuckets;
+	Entry *e;
+	Entry *p = NULL;
+
+	for (e= gh->buckets[hash]; e; e= e->next) {
+		if (gh->cmpfp(key, e->key)==0) {
+			Entry *n= e->next;
+
+			if (keyfreefp) keyfreefp(e->key);
+			if (valfreefp) valfreefp(e->val);
+			BLI_mempool_free(gh->entrypool, e);
+
+
+			e= n;
+			if (p)
+				p->next = n;
+			else
+				gh->buckets[hash] = n;
+
+			--gh->nentries;
+			return 1;
+		}
+		p = e;
+	}
+
+	return 0;
+}
+
+int BLI_ghash_haskey(GHash *gh, void *key) {
+	unsigned int hash= gh->hashfp(key)%gh->nbuckets;
+	Entry *e;
+
+	for (e= gh->buckets[hash]; e; e= e->next)
+		if (gh->cmpfp(key, e->key)==0)
+			return 1;
+
+	return 0;
+}
+
 void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp) {
 	int i;
 	




More information about the Bf-blender-cvs mailing list