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.
This commit is contained in:
Campbell Barton 2015-04-11 23:36:37 +10:00
parent 7447a0173c
commit ccf44c400c
3 changed files with 16 additions and 6 deletions

@ -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);

@ -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);

@ -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);