Skip to content

bpo-29736: Optimize builtin types constructor #519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 3 additions & 2 deletions Objects/boolobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ PyObject *PyBool_FromLong(long ok)
static PyObject *
bool_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
static char *kwlist[] = {"x", 0};
static const char * const kwlist[] = {"x", 0};
static _PyArg_Parser parser = {"|O:bool", kwlist, 0};
PyObject *x = Py_False;
long ok;

if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:bool", kwlist, &x))
if (!_PyArg_ParseTupleAndKeywordsFast(args, kwds, &parser, &x))
return NULL;
if (kwds != NULL && PyDict_GET_SIZE(kwds) != 0) {
if (PyErr_Warn(PyExc_DeprecationWarning,
Expand Down
7 changes: 4 additions & 3 deletions Objects/bytesobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2523,13 +2523,14 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
PyObject *new = NULL;
PyObject *func;
Py_ssize_t size;
static char *kwlist[] = {"source", "encoding", "errors", 0};
static const char * const kwlist[] = {"source", "encoding", "errors", 0};
static _PyArg_Parser parser = {"|Oss:bytes", kwlist, 0};
_Py_IDENTIFIER(__bytes__);

if (type != &PyBytes_Type)
return bytes_subtype_new(type, args, kwds);
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Oss:bytes", kwlist, &x,
&encoding, &errors))
if (!_PyArg_ParseTupleAndKeywordsFast(args, kwds, &parser, &x,
&encoding, &errors))
return NULL;
if (x == NULL) {
if (encoding != NULL || errors != NULL) {
Expand Down
6 changes: 3 additions & 3 deletions Objects/complexobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -921,12 +921,12 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
int own_r = 0;
int cr_is_complex = 0;
int ci_is_complex = 0;
static char *kwlist[] = {"real", "imag", 0};
static const char * const kwlist[] = {"real", "imag", 0};
static _PyArg_Parser parser = {"|OO:complex", kwlist, 0};

r = Py_False;
i = NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO:complex", kwlist,
&r, &i))
if (!_PyArg_ParseTupleAndKeywordsFast(args, kwds, &parser, &r, &i))
return NULL;

/* Special-case for a single argument when type(arg) is complex. */
Expand Down
5 changes: 3 additions & 2 deletions Objects/floatobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1563,11 +1563,12 @@ static PyObject *
float_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyObject *x = Py_False; /* Integer zero */
static char *kwlist[] = {"x", 0};
static const char * const kwlist[] = {"x", 0};
static _PyArg_Parser parser = {"|O:float", kwlist, 0};

if (type != &PyFloat_Type)
return float_subtype_new(type, args, kwds); /* Wimp out */
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:float", kwlist, &x))
if (!_PyArg_ParseTupleAndKeywordsFast(args, kwds, &parser, &x))
return NULL;
if (kwds != NULL && PyDict_GET_SIZE(kwds) != 0) {
if (PyErr_Warn(PyExc_DeprecationWarning,
Expand Down
5 changes: 3 additions & 2 deletions Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2293,9 +2293,10 @@ static int
list_init(PyListObject *self, PyObject *args, PyObject *kw)
{
PyObject *arg = NULL;
static char *kwlist[] = {"sequence", 0};
static const char * const kwlist[] = {"sequence", 0};
static _PyArg_Parser parser = {"|O:list", kwlist, 0};

if (!PyArg_ParseTupleAndKeywords(args, kw, "|O:list", kwlist, &arg))
if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &parser, &arg))
return -1;
if (arg != NULL && PyTuple_GET_SIZE(args) == 0) {
if (PyErr_Warn(PyExc_DeprecationWarning,
Expand Down
6 changes: 3 additions & 3 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -4796,12 +4796,12 @@ long_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyObject *obase = NULL, *x = NULL;
Py_ssize_t base;
static char *kwlist[] = {"x", "base", 0};
static const char * const kwlist[] = {"x", "base", 0};
static _PyArg_Parser parser = {"|OO:int", kwlist, 0};

if (type != &PyLong_Type)
return long_subtype_new(type, args, kwds); /* Wimp out */
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO:int", kwlist,
&x, &obase))
if (!_PyArg_ParseTupleAndKeywordsFast(args, kwds, &parser, &x, &obase))
return NULL;
if (x == NULL) {
if (obase != NULL) {
Expand Down
5 changes: 3 additions & 2 deletions Objects/tupleobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,11 +648,12 @@ static PyObject *
tuple_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyObject *arg = NULL;
static char *kwlist[] = {"sequence", 0};
static const char * const kwlist[] = {"sequence", 0};
static _PyArg_Parser parser = {"|O:tuple", kwlist, 0};

if (type != &PyTuple_Type)
return tuple_subtype_new(type, args, kwds);
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:tuple", kwlist, &arg))
if (!_PyArg_ParseTupleAndKeywordsFast(args, kwds, &parser, &arg))
return NULL;
if (arg != NULL && PyTuple_GET_SIZE(args) == 0) {
if (PyErr_Warn(PyExc_DeprecationWarning,
Expand Down
7 changes: 4 additions & 3 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -15001,14 +15001,15 @@ static PyObject *
unicode_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyObject *x = NULL;
static char *kwlist[] = {"object", "encoding", "errors", 0};
static const char * const kwlist[] = {"object", "encoding", "errors", 0};
static _PyArg_Parser parser = {"|Oss:str", kwlist, 0};
char *encoding = NULL;
char *errors = NULL;

if (type != &PyUnicode_Type)
return unicode_subtype_new(type, args, kwds);
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Oss:str",
kwlist, &x, &encoding, &errors))
if (!_PyArg_ParseTupleAndKeywordsFast(args, kwds, &parser,
&x, &encoding, &errors))
return NULL;
if (x == NULL)
_Py_RETURN_UNICODE_EMPTY();
Expand Down