mirror of
https://github.com/python/cpython.git
synced 2025-10-21 22:22:48 +00:00
sorted() uses METH_FASTCALL
This commit is contained in:
parent
fda6d0acf0
commit
5a60ecaa7a
1 changed files with 10 additions and 12 deletions
|
@ -2121,20 +2121,20 @@ PyDoc_STRVAR(builtin_sorted__doc__,
|
||||||
"reverse flag can be set to request the result in descending order.");
|
"reverse flag can be set to request the result in descending order.");
|
||||||
|
|
||||||
#define BUILTIN_SORTED_METHODDEF \
|
#define BUILTIN_SORTED_METHODDEF \
|
||||||
{"sorted", (PyCFunction)builtin_sorted, METH_VARARGS|METH_KEYWORDS, builtin_sorted__doc__},
|
{"sorted", (PyCFunction)builtin_sorted, METH_FASTCALL, builtin_sorted__doc__},
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
builtin_sorted(PyObject *self, PyObject *args, PyObject *kwds)
|
builtin_sorted(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
|
||||||
{
|
{
|
||||||
PyObject *newlist, *v, *seq, *keyfunc=NULL, **newargs;
|
PyObject *newlist, *v, *seq, *keyfunc=NULL;
|
||||||
PyObject *callable;
|
PyObject *callable;
|
||||||
static char *kwlist[] = {"iterable", "key", "reverse", 0};
|
static const char * const kwlist[] = {"iterable", "key", "reverse", 0};
|
||||||
int reverse;
|
|
||||||
Py_ssize_t nargs;
|
|
||||||
|
|
||||||
/* args 1-3 should match listsort in Objects/listobject.c */
|
/* args 1-3 should match listsort in Objects/listobject.c */
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|Oi:sorted",
|
static _PyArg_Parser parser = {"O|Oi:sorted", kwlist, 0};
|
||||||
kwlist, &seq, &keyfunc, &reverse))
|
int reverse;
|
||||||
|
|
||||||
|
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &parser,
|
||||||
|
&seq, &keyfunc, &reverse))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
newlist = PySequence_List(seq);
|
newlist = PySequence_List(seq);
|
||||||
|
@ -2147,9 +2147,7 @@ builtin_sorted(PyObject *self, PyObject *args, PyObject *kwds)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
newargs = &PyTuple_GET_ITEM(args, 1);
|
v = _PyObject_FastCallKeywords(callable, args + 1, nargs - 1, kwnames);
|
||||||
nargs = PyTuple_GET_SIZE(args) - 1;
|
|
||||||
v = _PyObject_FastCallDict(callable, newargs, nargs, kwds);
|
|
||||||
Py_DECREF(callable);
|
Py_DECREF(callable);
|
||||||
if (v == NULL) {
|
if (v == NULL) {
|
||||||
Py_DECREF(newlist);
|
Py_DECREF(newlist);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue