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
Linked PRs
Feature or enhancement
Proposal:
Currently
int.from_bytestakes aPyObject*and always converts it to abytesusingPyObject_Bytes. When a "bytes-like" object is passed in, such asbytearrayin_pylong, thePyObject_Bytesfunction has to make a newPyBytes*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_Bytessupports additional methods, such as.__bytes__()to construct thebytes, which should remain supported. That means need to keep doingbytes as bytes_obj: objectin Argument Clinic, rather thanbytes 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
Linked PRs