diff options
| author | Dan Engelbrecht <[email protected]> | 2023-08-21 13:41:22 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-08-21 13:41:22 +0200 |
| commit | 574afd9a5c286883ab40ff2ecb2cb229d7786712 (patch) | |
| tree | de98edde994699d38e045104778cee651e9ffe23 /src | |
| parent | use robinmap in compact cas (#368) (diff) | |
| download | zen-574afd9a5c286883ab40ff2ecb2cb229d7786712.tar.xz zen-574afd9a5c286883ab40ff2ecb2cb229d7786712.zip | |
use better hash function for better distribution in IoBuffer g_MappingLocks (#370)
* use better hash function for better distribution in IoBuffer g_MappingLocks
* changelog
Diffstat (limited to 'src')
| -rw-r--r-- | src/zencore/iobuffer.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/zencore/iobuffer.cpp b/src/zencore/iobuffer.cpp index f53d80778..22bc61395 100644 --- a/src/zencore/iobuffer.cpp +++ b/src/zencore/iobuffer.cpp @@ -249,11 +249,20 @@ static_assert(IsPow2(MappingLockCount), "MappingLockCount must be power of two") static RwLock g_MappingLocks[MappingLockCount]; +static uint64_t +HashPtr64(uint64_t x) +{ + x = (x ^ (x >> 30)) * UINT64_C(0xbf58476d1ce4e5b9); + x = (x ^ (x >> 27)) * UINT64_C(0x94d049bb133111eb); + x = x ^ (x >> 31); + return x; +} + static RwLock& MappingLockForInstance(const IoBufferExtendedCore* instance) { intptr_t base = (intptr_t)instance; - size_t lock_index = ((base >> 5) ^ (base >> 13)) & (MappingLockCount - 1u); + uint32_t lock_index = uint32_t(HashPtr64(uint64_t(base)) & (MappingLockCount - 1u)); return g_MappingLocks[lock_index]; } |