[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [23027] branches/bmesh/blender/source/ blender: more optimization stuff.
Joseph Eagar
joeedh at gmail.com
Sun Sep 6 04:43:37 CEST 2009
Revision: 23027
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23027
Author: joeedh
Date: 2009-09-06 04:43:36 +0200 (Sun, 06 Sep 2009)
Log Message:
-----------
more optimization stuff. transformed a few functions into macro that profiling showed were taking a bunch of time. also have some work-in-progress (if disabled) stuff related to inlining, which I'm trying to get working but may be too much trouble.
Modified Paths:
--------------
branches/bmesh/blender/source/blender/blenkernel/BKE_utildefines.h
branches/bmesh/blender/source/blender/blenlib/BLI_ghash.h
branches/bmesh/blender/source/blender/blenlib/intern/BLI_ghash.c
branches/bmesh/blender/source/blender/blenlib/intern/BLI_mempool.c
branches/bmesh/blender/source/blender/blenlib/intern/scanfill.c
branches/bmesh/blender/source/blender/bmesh/bmesh_iterators.h
branches/bmesh/blender/source/blender/bmesh/bmesh_operator_api.h
branches/bmesh/blender/source/blender/bmesh/intern/bmesh_mesh.c
branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c
branches/bmesh/blender/source/blender/bmesh/operators/mesh_conv.c
branches/bmesh/blender/source/blender/bmesh/operators/removedoubles.c
branches/bmesh/blender/source/blender/editors/transform/transform_conversions.c
branches/bmesh/blender/source/blender/editors/uvedit/uvedit_unwrap_ops.c
Modified: branches/bmesh/blender/source/blender/blenkernel/BKE_utildefines.h
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/BKE_utildefines.h 2009-09-06 01:51:23 UTC (rev 23026)
+++ branches/bmesh/blender/source/blender/blenkernel/BKE_utildefines.h 2009-09-06 02:43:36 UTC (rev 23027)
@@ -239,5 +239,14 @@
free the memory.*/
#define V_RESET(vec) _##vec##_count=0
+/*little macro so inline keyword works*/
+#if defined(_MSC_VER)
+#define BM_INLINE //__forceinline
+#else
+#define BM_INLINE inline
#endif
+#define BMEMSET(mem, val, size) {int _i; char *_c = mem; for (_i=0; _i<size; _i++) *_c++ = val;}
+
+#endif
+
Modified: branches/bmesh/blender/source/blender/blenlib/BLI_ghash.h
===================================================================
--- branches/bmesh/blender/source/blender/blenlib/BLI_ghash.h 2009-09-06 01:51:23 UTC (rev 23026)
+++ branches/bmesh/blender/source/blender/blenlib/BLI_ghash.h 2009-09-06 02:43:36 UTC (rev 23027)
@@ -32,27 +32,41 @@
#ifndef BLI_GHASH_H
#define BLI_GHASH_H
-struct GHash;
-typedef struct GHash GHash;
+#include "BKE_utildefines.h"
+typedef unsigned int (*GHashHashFP) (void *key);
+typedef int (*GHashCmpFP) (void *a, void *b);
+typedef void (*GHashKeyFreeFP) (void *key);
+typedef void (*GHashValFreeFP) (void *val);
+
+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;
+} GHash;
+
typedef struct GHashIterator {
GHash *gh;
int curBucket;
struct Entry *curEntry;
} GHashIterator;
-typedef unsigned int (*GHashHashFP) (void *key);
-typedef int (*GHashCmpFP) (void *a, void *b);
-typedef void (*GHashKeyFreeFP) (void *key);
-typedef void (*GHashValFreeFP) (void *val);
-
GHash* BLI_ghash_new (GHashHashFP hashfp, GHashCmpFP cmpfp);
void BLI_ghash_free (GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp);
-void BLI_ghash_insert (GHash *gh, void *key, void *val);
-int BLI_ghash_remove (GHash *gh, void *key, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp);
-void* BLI_ghash_lookup (GHash *gh, void *key);
-int BLI_ghash_haskey (GHash *gh, void *key);
+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);
int BLI_ghash_size (GHash *gh);
@@ -127,3 +141,29 @@
#endif
+/*begin of macro-inlined functions*/
+extern unsigned int hashsizes[];
+
+#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); } }
Modified: branches/bmesh/blender/source/blender/blenlib/intern/BLI_ghash.c
===================================================================
--- branches/bmesh/blender/source/blender/blenlib/intern/BLI_ghash.c 2009-09-06 01:51:23 UTC (rev 23026)
+++ branches/bmesh/blender/source/blender/blenlib/intern/BLI_ghash.c 2009-09-06 02:43:36 UTC (rev 23027)
@@ -37,13 +37,15 @@
#include "BLO_sys_types.h" // for intptr_t support
+#include "BKE_utildefines.h"
+
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
/***/
-static unsigned int hashsizes[]= {
+unsigned int hashsizes[]= {
1, 3, 5, 11, 17, 37, 67, 131, 257, 521, 1031, 2053, 4099, 8209,
16411, 32771, 65537, 131101, 262147, 524309, 1048583, 2097169,
4194319, 8388617, 16777259, 33554467, 67108879, 134217757,
@@ -52,29 +54,13 @@
/***/
-typedef struct Entry Entry;
-struct Entry {
- Entry *next;
-
- void *key, *val;
-};
-
-struct GHash {
- GHashHashFP hashfp;
- GHashCmpFP cmpfp;
-
- Entry **buckets;
- struct BLI_mempool *entrypool;
- int nbuckets, nentries, cursize;
-};
-
/***/
GHash *BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp) {
GHash *gh= MEM_mallocN(sizeof(*gh), "GHash");
gh->hashfp= hashfp;
gh->cmpfp= cmpfp;
- gh->entrypool = BLI_mempool_create(sizeof(Entry), 1, 32);
+ gh->entrypool = BLI_mempool_create(sizeof(Entry), 1024, 1024);
gh->cursize= 0;
gh->nentries= 0;
@@ -86,7 +72,11 @@
return gh;
}
-void BLI_ghash_insert(GHash *gh, void *key, void *val) {
+#ifdef BLI_ghash_insert
+#undef BLI_ghash_insert
+#endif
+
+BM_INLINE void BLI_ghash_insert(GHash *gh, void *key, void *val) {
unsigned int hash= gh->hashfp(key)%gh->nbuckets;
Entry *e= BLI_mempool_alloc(gh->entrypool);
@@ -119,7 +109,7 @@
}
}
-void* BLI_ghash_lookup(GHash *gh, void *key)
+BM_INLINE void* BLI_ghash_lookup(GHash *gh, void *key)
{
if(gh) {
unsigned int hash= gh->hashfp(key)%gh->nbuckets;
@@ -132,7 +122,7 @@
return NULL;
}
-int BLI_ghash_remove (GHash *gh, void *key, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
+BM_INLINE int BLI_ghash_remove (GHash *gh, void *key, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
{
unsigned int hash= gh->hashfp(key)%gh->nbuckets;
Entry *e;
@@ -162,7 +152,7 @@
return 0;
}
-int BLI_ghash_haskey(GHash *gh, void *key) {
+BM_INLINE int BLI_ghash_haskey(GHash *gh, void *key) {
unsigned int hash= gh->hashfp(key)%gh->nbuckets;
Entry *e;
Modified: branches/bmesh/blender/source/blender/blenlib/intern/BLI_mempool.c
===================================================================
--- branches/bmesh/blender/source/blender/blenlib/intern/BLI_mempool.c 2009-09-06 01:51:23 UTC (rev 23026)
+++ branches/bmesh/blender/source/blender/blenlib/intern/BLI_mempool.c 2009-09-06 02:43:36 UTC (rev 23027)
@@ -31,9 +31,14 @@
*/
#include "MEM_guardedalloc.h"
+
+#include "BKE_utildefines.h"
+
#include "BLI_blenlib.h"
+#include "BLI_linklist.h"
+
#include "DNA_listBase.h"
-#include "BLI_linklist.h"
+
#include <string.h>
typedef struct BLI_freenode{
@@ -122,7 +127,7 @@
void *BLI_mempool_calloc(BLI_mempool *pool){
void *retval=NULL;
retval = BLI_mempool_alloc(pool);
- memset(retval, 0, pool->esize);
+ BMEMSET(retval, 0, pool->esize);
return retval;
}
Modified: branches/bmesh/blender/source/blender/blenlib/intern/scanfill.c
===================================================================
--- branches/bmesh/blender/source/blender/blenlib/intern/scanfill.c 2009-09-06 01:51:23 UTC (rev 23026)
+++ branches/bmesh/blender/source/blender/blenlib/intern/scanfill.c 2009-09-06 02:43:36 UTC (rev 23027)
@@ -31,6 +31,7 @@
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
+#include <string.h>
#include "MEM_guardedalloc.h"
@@ -154,7 +155,7 @@
{
int blocksize= 16384;
static int offs= 0; /* the current free adress */
- static struct mem_elements *cur= 0;
+ static struct mem_elements *cur= 0, *first;
static ListBase lb= {0, 0};
void *adr;
@@ -162,6 +163,10 @@
printf("incorrect use of new_mem_element\n");
}
else if(size== -1) {
+ /*keep the first block*/
+ first = lb.first;
+ BLI_remlink(&lb, first);
+
cur= lb.first;
while(cur) {
MEM_freeN(cur->data);
@@ -169,6 +174,12 @@
}
BLI_freelistN(&lb);
+ /*reset the block we're keeping*/
+ BLI_addtail(&lb, first);
+ memset(first->data, 0, blocksize);
+ cur = first;
+ offs = 0;
+
return NULL;
}
@@ -770,6 +781,7 @@
- struct elements xs en ys are not used here: don't hide stuff in it
- edge flag ->f becomes 2 when it's a new edge
- mode: & 1 is check for crossings, then create edges (TO DO )
+ - mode: & 2 is enable shortest diagonal test for quads
*/
ListBase tempve, temped;
EditVert *eve;
@@ -798,17 +810,22 @@
float vec1[3], vec2[3];
eve = fillvertbase.first;
-
- /*use shortest diagonal for quad*/
- VecSubf(vec1, eve->co, eve->next->next->co);
- VecSubf(vec2, eve->next->co, eve->next->next->next->co);
-
- if (INPR(vec1, vec1) < INPR(vec2, vec2)) {
- addfillface(eve, eve->next, eve->next->next, 0);
- addfillface(eve->next->next, eve->next->next->next, eve, 0);
+
+ if (mode & 2) {
+ /*use shortest diagonal for quad*/
+ VecSubf(vec1, eve->co, eve->next->next->co);
+ VecSubf(vec2, eve->next->co, eve->next->next->next->co);
+
+ if (INPR(vec1, vec1) < INPR(vec2, vec2)) {
+ addfillface(eve, eve->next, eve->next->next, 0);
+ addfillface(eve->next->next, eve->next->next->next, eve, 0);
+ } else{
+ addfillface(eve->next, eve->next->next, eve->next->next->next, 0);
+ addfillface(eve->next->next->next, eve, eve->next, 0);
+ }
} else {
- addfillface(eve->next, eve->next->next, eve->next->next->next, 0);
- addfillface(eve->next->next->next, eve, eve->next, 0);
+ addfillface(eve, eve->next, eve->next->next, 0);
+ addfillface(eve->next->next, eve->next->next->next, eve, 0);
}
return 1;
}
Modified: branches/bmesh/blender/source/blender/bmesh/bmesh_iterators.h
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/bmesh_iterators.h 2009-09-06 01:51:23 UTC (rev 23026)
+++ branches/bmesh/blender/source/blender/bmesh/bmesh_iterators.h 2009-09-06 02:43:36 UTC (rev 23027)
@@ -16,7 +16,7 @@
/*Defines for passing to BMIter_New.
"OF" can be substituted for "around"
- so BM_VERTS_OF_MESH_OF_FACE means "vertices
+ so BM_VERTS_OF_FACE means "vertices
around a face."
*/
@@ -32,14 +32,13 @@
#define BM_LOOPS_OF_VERT 6
#define BM_FACES_OF_EDGE 7
#define BM_VERTS_OF_FACE 8
-#define BM_FACEVERTS_OF_FACE 9
-#define BM_EDGES_OF_FACE 10
-#define BM_LOOPS_OF_FACE 11
+#define BM_EDGES_OF_FACE 9
+#define BM_LOOPS_OF_FACE 10
/*iterate through loops around this loop, which are fetched
from the other faces in the radial cycle surrounding the
input loop's edge.*/
-#define BM_LOOPS_OF_LOOP 12
+#define BM_LOOPS_OF_LOOP 11
#define BM_ITER(ele, iter, bm, type, data) \
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list