Skip to content

Commit a162da2

Browse files
committed
Unroll first digit calculation in long_hash
1 parent 146f5aa commit a162da2

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Objects/longobject.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3676,7 +3676,13 @@ long_hash(PyObject *obj)
36763676
}
36773677
i = _PyLong_DigitCount(v);
36783678
sign = _PyLong_NonCompactSign(v);
3679-
x = 0;
3679+
3680+
// unroll first two digits
3681+
assert(i>=2);
3682+
--i;
3683+
x = v->long_value.ob_digit[i];
3684+
assert(x < _PyHASH_MODULUS);
3685+
36803686
while (--i >= 0) {
36813687
/* Here x is a quantity in the range [0, _PyHASH_MODULUS); we
36823688
want to compute x * 2**PyLong_SHIFT + v->long_value.ob_digit[i] modulo

0 commit comments

Comments
 (0)