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
55 changes: 55 additions & 0 deletions Objects/clinic/picklebufobject.c.h

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

36 changes: 25 additions & 11 deletions Objects/picklebufobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@
#include "pycore_weakref.h" // FT_CLEAR_WEAKREFS()
#include <stddef.h>

#include "clinic/picklebufobject.c.h"

/*[clinic input]
module pickle
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=6165c351cde067ba]*/

/*[clinic input]
class pickle.PickleBuffer "PyPickleBufferObject *" "&PyPickleBuffer_Type"
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=b334ecd891c9cbc2]*/

typedef struct {
PyObject_HEAD
/* The view exported by the original object */
Expand Down Expand Up @@ -66,19 +78,20 @@ PyPickleBuffer_Release(PyObject *obj)
return 0;
}

static PyObject *
picklebuf_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyPickleBufferObject *self;
PyObject *base;
char *keywords[] = {"", NULL};
/*[clinic input]
@vectorcall
@classmethod
pickle.PickleBuffer.__new__ as picklebuf_new
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:PickleBuffer",
keywords, &base)) {
return NULL;
}
base: object
/
[clinic start generated code]*/

self = (PyPickleBufferObject *) type->tp_alloc(type, 0);
static PyObject *
picklebuf_new_impl(PyTypeObject *type, PyObject *base)
/*[clinic end generated code: output=b8269110aace6998 input=0f1cdf375a70e71d]*/
{
PyPickleBufferObject *self = (PyPickleBufferObject *) type->tp_alloc(type, 0);
if (self == NULL) {
return NULL;
}
Expand Down Expand Up @@ -215,6 +228,7 @@ PyTypeObject PyPickleBuffer_Type = {
.tp_basicsize = sizeof(PyPickleBufferObject),
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
.tp_new = picklebuf_new,
.tp_vectorcall = picklebuf_vectorcall,

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.

Why add vector all? Is the PickleBuffer used in performance critical code?

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.

It is listed as speedup candidate in #162350. Benchmark above shows good 1.6x enhancement. This enhancement is free, the only cost to get the benefit is a bit refactor of code to add vectorcall. I think we can do it.

.tp_dealloc = picklebuf_dealloc,
.tp_traverse = picklebuf_traverse,
.tp_clear = picklebuf_clear,
Expand Down
Loading