Description
Feature or enhancement
Proposal:
Currently int.from_bytes
takes a PyObject*
and always converts it to a bytes
using PyObject_Bytes
. When a "bytes-like" object is passed in, such as bytearray
in _pylong
, the PyObject_Bytes
function has to make a new PyBytes*
and copy the data from the bytes-like into it. Utilize the buffer protocol, with a fallback to PyObject_Bytes, to remove that object allocation and copy making the conversion faster.
I think the fallback is needed because PyObject_Bytes
supports additional methods, such as .__bytes__()
to construct the bytes
, which should remain supported. That means need to keep doing bytes as bytes_obj: object
in Argument Clinic, rather than bytes as bytes_obj: Py_buffer
.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response