summaryrefslogtreecommitdiff
path: root/Modules/_functoolsmodule.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/_functoolsmodule.c')
-rw-r--r--Modules/_functoolsmodule.c60
1 files changed, 36 insertions, 24 deletions
diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c
index d785c4932b..fa5fad3e75 100644
--- a/Modules/_functoolsmodule.c
+++ b/Modules/_functoolsmodule.c
@@ -128,44 +128,60 @@ partial_call(partialobject *pto, PyObject *args, PyObject *kw)
{
PyObject *ret;
PyObject *argappl, *kwappl;
+ PyObject **stack;
+ Py_ssize_t nargs;
assert (PyCallable_Check(pto->fn));
assert (PyTuple_Check(pto->args));
assert (PyDict_Check(pto->kw));
if (PyTuple_GET_SIZE(pto->args) == 0) {
- argappl = args;
- Py_INCREF(args);
- } else if (PyTuple_GET_SIZE(args) == 0) {
- argappl = pto->args;
- Py_INCREF(pto->args);
- } else {
+ stack = &PyTuple_GET_ITEM(args, 0);
+ nargs = PyTuple_GET_SIZE(args);
+ argappl = NULL;
+ }
+ else if (PyTuple_GET_SIZE(args) == 0) {
+ stack = &PyTuple_GET_ITEM(pto->args, 0);
+ nargs = PyTuple_GET_SIZE(pto->args);
+ argappl = NULL;
+ }
+ else {
+ stack = NULL;
argappl = PySequence_Concat(pto->args, args);
- if (argappl == NULL)
+ if (argappl == NULL) {
return NULL;
+ }
+
assert(PyTuple_Check(argappl));
}
if (PyDict_Size(pto->kw) == 0) {
kwappl = kw;
Py_XINCREF(kwappl);
- } else {
+ }
+ else {
kwappl = PyDict_Copy(pto->kw);
if (kwappl == NULL) {
- Py_DECREF(argappl);
+ Py_XDECREF(argappl);
return NULL;
}
+
if (kw != NULL) {
if (PyDict_Merge(kwappl, kw, 1) != 0) {
- Py_DECREF(argappl);
+ Py_XDECREF(argappl);
Py_DECREF(kwappl);
return NULL;
}
}
}
- ret = PyObject_Call(pto->fn, argappl, kwappl);
- Py_DECREF(argappl);
+ if (stack) {
+ ret = _PyObject_FastCallDict(pto->fn, stack, nargs, kwappl);
+ }
+ else {
+ ret = PyObject_Call(pto->fn, argappl, kwappl);
+ Py_DECREF(argappl);
+ }
Py_XDECREF(kwappl);
return ret;
}
@@ -213,7 +229,7 @@ partial_repr(partialobject *pto)
if (status != 0) {
if (status < 0)
return NULL;
- return PyUnicode_FromFormat("%s(...)", Py_TYPE(pto)->tp_name);
+ return PyUnicode_FromString("...");
}
arglist = PyUnicode_FromString("");
@@ -461,12 +477,12 @@ static PyObject *
keyobject_richcompare(PyObject *ko, PyObject *other, int op)
{
PyObject *res;
- PyObject *args;
PyObject *x;
PyObject *y;
PyObject *compare;
PyObject *answer;
static PyObject *zero;
+ PyObject* stack[2];
if (zero == NULL) {
zero = PyLong_FromLong(0);
@@ -490,17 +506,13 @@ keyobject_richcompare(PyObject *ko, PyObject *other, int op)
/* Call the user's comparison function and translate the 3-way
* result into true or false (or error).
*/
- args = PyTuple_New(2);
- if (args == NULL)
- return NULL;
- Py_INCREF(x);
- Py_INCREF(y);
- PyTuple_SET_ITEM(args, 0, x);
- PyTuple_SET_ITEM(args, 1, y);
- res = PyObject_Call(compare, args, NULL);
- Py_DECREF(args);
- if (res == NULL)
+ stack[0] = x;
+ stack[1] = y;
+ res = _PyObject_FastCall(compare, stack, 2);
+ if (res == NULL) {
return NULL;
+ }
+
answer = PyObject_RichCompare(res, zero, op);
Py_DECREF(res);
return answer;