Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 5a60eca

Browse files
committed
sorted() uses METH_FASTCALL
1 parent fda6d0a commit 5a60eca

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

Python/bltinmodule.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,20 +2121,20 @@ PyDoc_STRVAR(builtin_sorted__doc__,
21212121
"reverse flag can be set to request the result in descending order.");
21222122

21232123
#define BUILTIN_SORTED_METHODDEF \
2124-
{"sorted", (PyCFunction)builtin_sorted, METH_VARARGS|METH_KEYWORDS, builtin_sorted__doc__},
2124+
{"sorted", (PyCFunction)builtin_sorted, METH_FASTCALL, builtin_sorted__doc__},
21252125

21262126
static PyObject *
2127-
builtin_sorted(PyObject *self, PyObject *args, PyObject *kwds)
2127+
builtin_sorted(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
21282128
{
2129-
PyObject *newlist, *v, *seq, *keyfunc=NULL, **newargs;
2129+
PyObject *newlist, *v, *seq, *keyfunc=NULL;
21302130
PyObject *callable;
2131-
static char *kwlist[] = {"iterable", "key", "reverse", 0};
2131+
static const char * const kwlist[] = {"iterable", "key", "reverse", 0};
2132+
/* args 1-3 should match listsort in Objects/listobject.c */
2133+
static _PyArg_Parser parser = {"O|Oi:sorted", kwlist, 0};
21322134
int reverse;
2133-
Py_ssize_t nargs;
21342135

2135-
/* args 1-3 should match listsort in Objects/listobject.c */
2136-
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|Oi:sorted",
2137-
kwlist, &seq, &keyfunc, &reverse))
2136+
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &parser,
2137+
&seq, &keyfunc, &reverse))
21382138
return NULL;
21392139

21402140
newlist = PySequence_List(seq);
@@ -2147,9 +2147,7 @@ builtin_sorted(PyObject *self, PyObject *args, PyObject *kwds)
21472147
return NULL;
21482148
}
21492149

2150-
newargs = &PyTuple_GET_ITEM(args, 1);
2151-
nargs = PyTuple_GET_SIZE(args) - 1;
2152-
v = _PyObject_FastCallDict(callable, newargs, nargs, kwds);
2150+
v = _PyObject_FastCallKeywords(callable, args + 1, nargs - 1, kwnames);
21532151
Py_DECREF(callable);
21542152
if (v == NULL) {
21552153
Py_DECREF(newlist);

0 commit comments

Comments
 (0)