File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed
Misc/NEWS.d/next/Core_and_Builtins Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change 1+ Improve performance of :class: `int ` hash calculations.
Original file line number Diff line number Diff line change @@ -3676,7 +3676,23 @@ long_hash(PyObject *obj)
36763676 }
36773677 i = _PyLong_DigitCount (v );
36783678 sign = _PyLong_NonCompactSign (v );
3679- x = 0 ;
3679+
3680+ // unroll first digit
3681+ Py_BUILD_ASSERT (PyHASH_BITS > PyLong_SHIFT );
3682+ assert (i >= 1 );
3683+ -- i ;
3684+ x = v -> long_value .ob_digit [i ];
3685+ assert (x < PyHASH_MODULUS );
3686+
3687+ #if PyHASH_BITS >= 2 * PyLong_SHIFT
3688+ // unroll second digit
3689+ assert (i >= 1 );
3690+ -- i ;
3691+ x <<= PyLong_SHIFT ;
3692+ x += v -> long_value .ob_digit [i ];
3693+ assert (x < PyHASH_MODULUS );
3694+ #endif
3695+
36803696 while (-- i >= 0 ) {
36813697 /* Here x is a quantity in the range [0, _PyHASH_MODULUS); we
36823698 want to compute x * 2**PyLong_SHIFT + v->long_value.ob_digit[i] modulo
You can’t perform that action at this time.
0 commit comments