Issue #16674: random.getrandbits() is now 20-40% faster for small integers.
This commit is contained in:
parent
ca6142948e
commit
d8a0bac8f7
|
@ -201,6 +201,8 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #16674: random.getrandbits() is now 20-40% faster for small integers.
|
||||||
|
|
||||||
- Issue #16009: JSON error messages now provide more information.
|
- Issue #16009: JSON error messages now provide more information.
|
||||||
|
|
||||||
- Issue #16828: Fix error incorrectly raised by bz2.compress(b'') and
|
- Issue #16828: Fix error incorrectly raised by bz2.compress(b'') and
|
||||||
|
|
|
@ -360,6 +360,9 @@ random_getrandbits(RandomObject *self, PyObject *args)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (k <= 32) /* Fast path */
|
||||||
|
return PyLong_FromUnsignedLong(genrand_int32(self) >> (32 - k));
|
||||||
|
|
||||||
bytes = ((k - 1) / 32 + 1) * 4;
|
bytes = ((k - 1) / 32 + 1) * 4;
|
||||||
bytearray = (unsigned char *)PyMem_Malloc(bytes);
|
bytearray = (unsigned char *)PyMem_Malloc(bytes);
|
||||||
if (bytearray == NULL) {
|
if (bytearray == NULL) {
|
||||||
|
|
Loading…
Reference in New Issue