print now uses METH_FASTCALL

refer python/cpython@c3858bd7c6
refer python/cpython@bd584f169f
refer python/cpython@06d34393c2
This commit is contained in:
ahgamut 2021-11-05 02:12:57 +05:30
parent 7fb46fb510
commit d220f6f9b2
2 changed files with 14 additions and 14 deletions

View file

@ -2422,10 +2422,12 @@ _PyObject_Call_Prepend(PyObject *callable,
PyObject * PyObject *
_PyStack_AsDict(PyObject **values, PyObject *kwnames) _PyStack_AsDict(PyObject **values, PyObject *kwnames)
{ {
Py_ssize_t nkwargs = PyTuple_GET_SIZE(kwnames); Py_ssize_t nkwargs;
PyObject *kwdict; PyObject *kwdict;
Py_ssize_t i; Py_ssize_t i;
assert(kwnames != NULL);
nkwargs = PyTuple_GET_SIZE(kwnames);
kwdict = _PyDict_NewPresized(nkwargs); kwdict = _PyDict_NewPresized(nkwargs);
if (kwdict == NULL) { if (kwdict == NULL) {
return NULL; return NULL;
@ -2434,8 +2436,6 @@ _PyStack_AsDict(PyObject **values, PyObject *kwnames)
for (i = 0; i < nkwargs; i++) { for (i = 0; i < nkwargs; i++) {
PyObject *key = PyTuple_GET_ITEM(kwnames, i); PyObject *key = PyTuple_GET_ITEM(kwnames, i);
PyObject *value = *values++; PyObject *value = *values++;
assert(PyUnicode_CheckExact(key));
assert(PyDict_GetItem(kwdict, key) == NULL);
if (PyDict_SetItem(kwdict, key, value)) { if (PyDict_SetItem(kwdict, key, value)) {
Py_DECREF(kwdict); Py_DECREF(kwdict);
return NULL; return NULL;

View file

@ -1936,18 +1936,19 @@ builtin_pow_impl(PyObject *module, PyObject *x, PyObject *y, PyObject *z)
/* AC: cannot convert yet, waiting for *args support */ /* AC: cannot convert yet, waiting for *args support */
static PyObject * static PyObject *
builtin_print(PyObject *self, PyObject *args, PyObject *kwds) builtin_print(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
{ {
static char *kwlist[] = {"sep", "end", "file", "flush", 0}; static const char * const _keywords[] = {"sep", "end", "file", "flush", 0};
static PyObject *dummy_args; static struct _PyArg_Parser _parser = {"|OOOO:print", _keywords, 0};
PyObject *sep = NULL, *end = NULL, *file = NULL, *flush = NULL; PyObject *sep = NULL, *end = NULL, *file = NULL, *flush = NULL;
int i, err; int i, err;
if (dummy_args == NULL && !(dummy_args = PyTuple_New(0))) if (kwnames != NULL &&
return NULL; !_PyArg_ParseStackAndKeywords(args + nargs, 0, kwnames, &_parser,
if (!PyArg_ParseTupleAndKeywords(dummy_args, kwds, "|OOOO:print", &sep, &end, &file, &flush)) {
kwlist, &sep, &end, &file, &flush))
return NULL; return NULL;
}
if (file == NULL || file == Py_None) { if (file == NULL || file == Py_None) {
file = _PySys_GetObjectId(&PyId_stdout); file = _PySys_GetObjectId(&PyId_stdout);
if (file == NULL) { if (file == NULL) {
@ -1979,7 +1980,7 @@ builtin_print(PyObject *self, PyObject *args, PyObject *kwds)
return NULL; return NULL;
} }
for (i = 0; i < PyTuple_Size(args); i++) { for (i = 0; i < nargs; i++) {
if (i > 0) { if (i > 0) {
if (sep == NULL) if (sep == NULL)
err = PyFile_WriteString(" ", file); err = PyFile_WriteString(" ", file);
@ -1989,8 +1990,7 @@ builtin_print(PyObject *self, PyObject *args, PyObject *kwds)
if (err) if (err)
return NULL; return NULL;
} }
err = PyFile_WriteObject(PyTuple_GetItem(args, i), file, err = PyFile_WriteObject(args[i], file, Py_PRINT_RAW);
Py_PRINT_RAW);
if (err) if (err)
return NULL; return NULL;
} }
@ -2854,7 +2854,7 @@ static PyMethodDef builtin_methods[] = {
BUILTIN_OCT_METHODDEF BUILTIN_OCT_METHODDEF
BUILTIN_ORD_METHODDEF BUILTIN_ORD_METHODDEF
BUILTIN_POW_METHODDEF BUILTIN_POW_METHODDEF
{"print", (PyCFunction)builtin_print, METH_VARARGS | METH_KEYWORDS, print_doc}, {"print", (PyCFunction)builtin_print, METH_FASTCALL, print_doc},
BUILTIN_REPR_METHODDEF BUILTIN_REPR_METHODDEF
{"round", (PyCFunction)builtin_round, METH_VARARGS | METH_KEYWORDS, round_doc}, {"round", (PyCFunction)builtin_round, METH_VARARGS | METH_KEYWORDS, round_doc},
BUILTIN_SETATTR_METHODDEF BUILTIN_SETATTR_METHODDEF