Kaydet (Commit) 76a4b896 authored tarafından Antoine Pitrou's avatar Antoine Pitrou

Issue #5186: Reduce hash collisions for objects with no __hash__ method by

rotating the object pointer by 4 bits to the right.
üst 2c079297
...@@ -12,6 +12,9 @@ What's New in Python 2.7 alpha 1 ...@@ -12,6 +12,9 @@ What's New in Python 2.7 alpha 1
Core and Builtins Core and Builtins
----------------- -----------------
- Issue #5186: Reduce hash collisions for objects with no __hash__ method by
rotating the object pointer by 4 bits to the right.
- Issue #4575: Fix Py_IS_INFINITY macro to work correctly on x87 FPUs: - Issue #4575: Fix Py_IS_INFINITY macro to work correctly on x87 FPUs:
it now forces its argument to double before testing for infinity. it now forces its argument to double before testing for infinity.
......
...@@ -1072,23 +1072,15 @@ _Py_HashDouble(double v) ...@@ -1072,23 +1072,15 @@ _Py_HashDouble(double v)
long long
_Py_HashPointer(void *p) _Py_HashPointer(void *p)
{ {
#if SIZEOF_LONG >= SIZEOF_VOID_P
return (long)p;
#else
/* convert to a Python long and hash that */
PyObject* longobj;
long x; long x;
size_t y = (size_t)p;
if ((longobj = PyLong_FromVoidPtr(p)) == NULL) { /* bottom 3 or 4 bits are likely to be 0; rotate y by 4 to avoid
x = -1; excessive hash collisions for dicts and sets */
goto finally; y = (y >> 4) | (y << 8*SIZEOF_VOID_P - 4);
} x = (long)y;
x = PyObject_Hash(longobj); if (x == -1)
x = -2;
finally:
Py_XDECREF(longobj);
return x; return x;
#endif
} }
long long
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment