]> granicus.if.org Git - python/commitdiff
Issue #27128: slot_sq_item() uses fast call
authorVictor Stinner <victor.stinner@gmail.com>
Fri, 19 Aug 2016 16:19:42 +0000 (18:19 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Fri, 19 Aug 2016 16:19:42 +0000 (18:19 +0200)
slot_sq_item() now calls _PyObject_FastCall() to avoid the creation of a
temporary tuple of 1 item to pass the 'item' argument to the slot function.

Objects/typeobject.c

index ff9f0204e90357b0fb93e6c7139f922aeb5567a3..364841b0b4b71070b3f566d61f33b8ce53761ac3 100644 (file)
@@ -5808,7 +5808,7 @@ slot_sq_length(PyObject *self)
 static PyObject *
 slot_sq_item(PyObject *self, Py_ssize_t i)
 {
-    PyObject *func, *ival = NULL, *args, *retval = NULL;
+    PyObject *func, *ival = NULL, *retval = NULL;
     descrgetfunc f;
 
     func = _PyType_LookupId(Py_TYPE(self), &PyId___getitem__);
@@ -5834,20 +5834,13 @@ slot_sq_item(PyObject *self, Py_ssize_t i)
         goto error;
     }
 
-    args = PyTuple_New(1);
-    if (args == NULL) {
-        goto error;
-    }
-
-    PyTuple_SET_ITEM(args, 0, ival);
-    retval = PyObject_Call(func, args, NULL);
+    retval = _PyObject_FastCall(func, &ival, 1, NULL);
     Py_DECREF(func);
-    Py_DECREF(args);
+    Py_DECREF(ival);
     return retval;
 
 error:
     Py_DECREF(func);
-    Py_XDECREF(ival);
     return NULL;
 }