Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(30261)

Unified Diff: Python/bltinmodule.c

Issue 29296: convert print() to METH_FASTCALL
Patch Set: Created 2 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Python/bltinmodule.c Tue Jan 17 12:47:18 2017 +0200
+++ b/Python/bltinmodule.c Tue Jan 17 20:29:19 2017 +0900
@@ -1736,18 +1736,19 @@ builtin_pow_impl(PyObject *module, PyObj
/* AC: cannot convert yet, waiting for *args support */
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 PyObject *dummy_args;
+ static const char * const _keywords[] = {"sep", "end", "file", "flush", 0};
+ static struct _PyArg_Parser _parser = {"|OOOO:print", _keywords, 0};
PyObject *sep = NULL, *end = NULL, *file = NULL, *flush = NULL;
int i, err;
- if (dummy_args == NULL && !(dummy_args = PyTuple_New(0)))
+ if (kwnames != NULL &&
+ !_PyArg_ParseStackAndKeywords(args + nargs, 0, kwnames, &_parser,
haypo 2017/01/17 17:55:44 You can pass NULL as the first parameter. Nice tr
+ &sep, &end, &file, &flush)) {
return NULL;
- if (!PyArg_ParseTupleAndKeywords(dummy_args, kwds, "|OOOO:print",
- kwlist, &sep, &end, &file, &flush))
- return NULL;
+ }
+
if (file == NULL || file == Py_None) {
file = _PySys_GetObjectId(&PyId_stdout);
if (file == NULL) {
@@ -1779,7 +1780,7 @@ builtin_print(PyObject *self, PyObject *
return NULL;
}
- for (i = 0; i < PyTuple_Size(args); i++) {
+ for (i = 0; i < nargs; i++) {
if (i > 0) {
if (sep == NULL)
err = PyFile_WriteString(" ", file);
@@ -1789,8 +1790,7 @@ builtin_print(PyObject *self, PyObject *
if (err)
return NULL;
}
- err = PyFile_WriteObject(PyTuple_GetItem(args, i), file,
- Py_PRINT_RAW);
+ err = PyFile_WriteObject(args[i], file, Py_PRINT_RAW);
if (err)
return NULL;
}
@@ -2640,7 +2640,7 @@ static PyMethodDef builtin_methods[] = {
BUILTIN_OCT_METHODDEF
BUILTIN_ORD_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
{"round", (PyCFunction)builtin_round, METH_VARARGS | METH_KEYWORDS, round_doc},
BUILTIN_SETATTR_METHODDEF
« no previous file with comments | « no previous file | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+