mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
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().
This commit is contained in:
parent
f8852634ed
commit
828451dfde
9 changed files with 103 additions and 22 deletions
|
@ -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)
|
||||
Py_HashPointer(const void *ptr)
|
||||
{
|
||||
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_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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue