镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Speed up :class:`bytes` and :class:`bytearray` construction by adding

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The vectorcall changes look good. But the optimizations need a second look. For example:

>>> import bisect
>>> lst = []
>>> bisect.insort(lst, bytearray(b'abc')[1:], key=bytes)
>>> lst
[bytearray(b'')]      # main: [bytearray(b'bc')]

For that reason maybe split the PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Splitting the PR

It looks like this gets broken because a lot of the stack uses "borrowed" references which make it look like it's uniquely referenced when it is still in use in multiple paths.... Still want to do the no-copy optimization and the similar one with iconcat but clearly still need some different tools.

:ref:`vectorcall` support.
4 changes: 3 additions & 1 deletion Objects/bytearrayobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,7 @@ bytearray_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}

/*[clinic input]
@vectorcall
bytearray.__init__

source as arg: object = NULL
Expand All @@ -988,7 +989,7 @@ bytearray.__init__
static int
bytearray___init___impl(PyByteArrayObject *self, PyObject *arg,
const char *encoding, const char *errors)
/*[clinic end generated code: output=4ce1304649c2f8b3 input=1141a7122eefd7b9]*/
/*[clinic end generated code: output=4ce1304649c2f8b3 input=24ddb84055f432dd]*/
{
Py_ssize_t count;
PyObject *it;
Expand Down Expand Up @@ -3027,6 +3028,7 @@ PyTypeObject PyByteArray_Type = {
PyType_GenericAlloc, /* tp_alloc */
bytearray_new, /* tp_new */
PyObject_Free, /* tp_free */
.tp_vectorcall = bytearray_vectorcall,
.tp_version_tag = _Py_TYPE_VERSION_BYTEARRAY,
};

Expand Down
4 changes: 3 additions & 1 deletion Objects/bytesobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2918,6 +2918,7 @@ static PyObject *
bytes_subtype_new(PyTypeObject *, PyObject *);

/*[clinic input]
@vectorcall
@classmethod
bytes.__new__ as bytes_new

Expand All @@ -2930,7 +2931,7 @@ bytes.__new__ as bytes_new
static PyObject *
bytes_new_impl(PyTypeObject *type, PyObject *x, const char *encoding,
const char *errors)
/*[clinic end generated code: output=1e0c471be311a425 input=f0a966d19b7262b4]*/
/*[clinic end generated code: output=1e0c471be311a425 input=b0248d22e221a095]*/
{
PyObject *bytes;
PyObject *func;
Expand Down Expand Up @@ -3316,6 +3317,7 @@ PyTypeObject PyBytes_Type = {
bytes_type_alloc, /* tp_alloc */
bytes_new, /* tp_new */
PyObject_Free, /* tp_free */
.tp_vectorcall = bytes_vectorcall,
.tp_version_tag = _Py_TYPE_VERSION_BYTES,
._tp_iteritem = bytes_iteritem,
};
Expand Down
95 changes: 89 additions & 6 deletions Objects/clinic/bytearrayobject.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 66 additions & 5 deletions Objects/clinic/bytesobject.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading