diff options
author | Victor Stinner <vstinner@python.org> | 2023-12-06 14:09:22 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-06 14:09:22 (GMT) |
commit | 828451dfde324f9499ffebc023a22b84dc5a125b (patch) | |
tree | ceee17c26f9c9238b602ef9156e6eb8530d032f1 /Python/pyhash.c | |
parent | f8852634edf1232ac1aa4561e34796b52f9f7aa2 (diff) | |
download | cpython-828451dfde324f9499ffebc023a22b84dc5a125b.zip cpython-828451dfde324f9499ffebc023a22b84dc5a125b.tar.gz cpython-828451dfde324f9499ffebc023a22b84dc5a125b.tar.bz2 |
gh-111545: Add Py_HashPointer() function (#112096)
* Implement _Py_HashPointerRaw() as a static inline function.
* Add Py_HashPointer() tests to test_capi.test_hash.
* Keep _Py_HashPointer() function as an alias to Py_HashPointer().
Diffstat (limited to 'Python/pyhash.c')
-rw-r--r-- | Python/pyhash.c | 22 |
1 files changed, 5 insertions, 17 deletions
diff --git a/Python/pyhash.c b/Python/pyhash.c index f9060b8..141407c 100644 --- a/Python/pyhash.c +++ b/Python/pyhash.c @@ -83,8 +83,6 @@ static Py_ssize_t hashstats[Py_HASH_STATS_MAX + 1] = {0}; */ -Py_hash_t _Py_HashPointer(const void *); - Py_hash_t _Py_HashDouble(PyObject *inst, double v) { @@ -132,23 +130,13 @@ _Py_HashDouble(PyObject *inst, double v) } Py_hash_t -_Py_HashPointerRaw(const void *p) -{ - size_t y = (size_t)p; - /* 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_P - 4)); - return (Py_hash_t)y; -} - -Py_hash_t -_Py_HashPointer(const void *p) +Py_HashPointer(const void *ptr) { - Py_hash_t x = _Py_HashPointerRaw(p); - if (x == -1) { - x = -2; + Py_hash_t hash = _Py_HashPointerRaw(ptr); + if (hash == -1) { + hash = -2; } - return x; + return hash; } Py_hash_t |