[Bf-blender-cvs] [ccf44c4] master: BMesh: simplify hashing for dyntopo

Campbell Barton noreply at git.blender.org
Sat Apr 11 15:42:05 CEST 2015


Commit: ccf44c400c896761c87836a06be24216c366c87b
Author: Campbell Barton
Date:   Sat Apr 11 23:36:37 2015 +1000
Branches: master
https://developer.blender.org/rBccf44c400c896761c87836a06be24216c366c87b

BMesh: simplify hashing for dyntopo

Was using pointer hashing when the keys are in fact uint's.
Since they're well distributed from the rangetree,
no need to do bit-shifting tricks. just use int as hash.
Gives ~8% speedup in own tests.

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

M	source/blender/blenlib/BLI_ghash.h
M	source/blender/blenlib/intern/BLI_ghash.c
M	source/blender/bmesh/intern/bmesh_log.c

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

diff --git a/source/blender/blenlib/BLI_ghash.h b/source/blender/blenlib/BLI_ghash.h
index a00ddee..f287cf7 100644
--- a/source/blender/blenlib/BLI_ghash.h
+++ b/source/blender/blenlib/BLI_ghash.h
@@ -148,6 +148,7 @@ bool            BLI_ghashutil_strcmp(const void *a, const void *b);
 unsigned int    BLI_ghashutil_uinthash(unsigned int key);
 unsigned int    BLI_ghashutil_inthash_p(const void *ptr);
 unsigned int    BLI_ghashutil_inthash_p_murmur(const void *ptr);
+unsigned int    BLI_ghashutil_inthash_p_simple(const void *ptr);
 bool            BLI_ghashutil_intcmp(const void *a, const void *b);
 
 
diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c
index dae7af6..484fe70 100644
--- a/source/blender/blenlib/intern/BLI_ghash.c
+++ b/source/blender/blenlib/intern/BLI_ghash.c
@@ -1091,6 +1091,11 @@ unsigned int BLI_ghashutil_inthash_p_murmur(const void *ptr)
 	return BLI_hash_mm2((const unsigned char *)&key, sizeof(key), 0);
 }
 
+unsigned int BLI_ghashutil_inthash_p_simple(const void *ptr)
+{
+	return GET_UINT_FROM_POINTER(ptr);
+}
+
 bool BLI_ghashutil_intcmp(const void *a, const void *b)
 {
 	return (a != b);
diff --git a/source/blender/bmesh/intern/bmesh_log.c b/source/blender/bmesh/intern/bmesh_log.c
index c53b7f9..25ddb9e 100644
--- a/source/blender/bmesh/intern/bmesh_log.c
+++ b/source/blender/bmesh/intern/bmesh_log.c
@@ -126,6 +126,10 @@ typedef struct {
 
 /************************* Get/set element IDs ************************/
 
+/* bypass actual hashing, the keys don't overlap */
+#define logkey_hash BLI_ghashutil_inthash_p_simple
+#define logkey_cmp BLI_ghashutil_intcmp
+
 /* Get the vertex's unique ID from the log */
 static unsigned int bm_log_vert_id_get(BMLog *log, BMVert *v)
 {
@@ -386,12 +390,12 @@ static BMLogEntry *bm_log_entry_create(void)
 {
 	BMLogEntry *entry = MEM_callocN(sizeof(BMLogEntry), __func__);
 
-	entry->deleted_verts = BLI_ghash_ptr_new(__func__);
-	entry->deleted_faces = BLI_ghash_ptr_new(__func__);
-	entry->added_verts = BLI_ghash_ptr_new(__func__);
-	entry->added_faces = BLI_ghash_ptr_new(__func__);
-	entry->modified_verts = BLI_ghash_ptr_new(__func__);
-	entry->modified_faces = BLI_ghash_ptr_new(__func__);
+	entry->deleted_verts = BLI_ghash_new(logkey_hash, logkey_cmp, __func__);
+	entry->deleted_faces = BLI_ghash_new(logkey_hash, logkey_cmp, __func__);
+	entry->added_verts = BLI_ghash_new(logkey_hash, logkey_cmp, __func__);
+	entry->added_faces = BLI_ghash_new(logkey_hash, logkey_cmp, __func__);
+	entry->modified_verts = BLI_ghash_new(logkey_hash, logkey_cmp, __func__);
+	entry->modified_faces = BLI_ghash_new(logkey_hash, logkey_cmp, __func__);
 
 	entry->pool_verts = BLI_mempool_create(sizeof(BMLogVert), 0, 64, BLI_MEMPOOL_NOP);
 	entry->pool_faces = BLI_mempool_create(sizeof(BMLogFace), 0, 64, BLI_MEMPOOL_NOP);




More information about the Bf-blender-cvs mailing list