diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-11-04 08:44:28 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-11-04 08:48:36 +0300 |
commit | 76b9eaf7a84ee2098c1ca1bf5cd4042c55ae76d7 (patch) | |
tree | 5140422110f3c65b6a0ac062d0ade196b1439511 /source | |
parent | 1b974563b17b3a1ee02d81df952a66ecf66919c4 (diff) |
Fix ghash masking out upper bits on 64bit systems
The code this was taken from assumes a 'size_t' result,
which isn't the case here.
In practice the bucket distribution wasn't bad,
even so this was a nop so best fix.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenlib/intern/BLI_ghash_utils.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/source/blender/blenlib/intern/BLI_ghash_utils.c b/source/blender/blenlib/intern/BLI_ghash_utils.c index 953ceb3442b..a0d9fefe465 100644 --- a/source/blender/blenlib/intern/BLI_ghash_utils.c +++ b/source/blender/blenlib/intern/BLI_ghash_utils.c @@ -54,14 +54,16 @@ uint BLI_ghashutil_ptrhash(const void *key) return (uint)(intptr_t)key; } #else -/* based python3.3's pointer hashing function */ +/* Based Python3.7's pointer hashing function. */ uint BLI_ghashutil_ptrhash(const void *key) { size_t y = (size_t)key; /* bottom 3 or 4 bits are likely to be 0; rotate y by 4 to avoid * excessive hash collisions for dicts and sets */ - y = (y >> 4) | (y << (8 * sizeof(void *) - 4)); - return (uint)y; + + /* Note: Unlike Python 'sizeof(uint)' is used instead of 'sizeof(void *)', + * Otherwise casting to 'uint' ignores the upper bits on 64bit platforms. */ + return (uint)(y >> 4) | ((uint)y << (8 * sizeof(uint) - 4)); } #endif bool BLI_ghashutil_ptrcmp(const void *a, const void *b) |