]> granicus.if.org Git - python/commitdiff
Avoid inefficient way to call functions without argument
authorVictor Stinner <victor.stinner@gmail.com>
Tue, 6 Sep 2016 00:53:15 +0000 (17:53 -0700)
committerVictor Stinner <victor.stinner@gmail.com>
Tue, 6 Sep 2016 00:53:15 +0000 (17:53 -0700)
Don't pass "()" format to PyObject_CallXXX() to call a function without
argument: pass NULL as the format string instead. It avoids to have to parse a
string to produce 0 argument.

Modules/_collectionsmodule.c
Modules/_datetimemodule.c
Modules/_pickle.c
Objects/typeobject.c
Python/modsupport.c

index 3410dfec07f8593b58599adc682a1647a2d5eb0d..167510268167b6e43848339ed9f9f96c0668c930 100644 (file)
@@ -2009,7 +2009,7 @@ defdict_reduce(defdictobject *dd)
         args = PyTuple_Pack(1, dd->default_factory);
     if (args == NULL)
         return NULL;
-    items = _PyObject_CallMethodId((PyObject *)dd, &PyId_items, "()");
+    items = _PyObject_CallMethodId((PyObject *)dd, &PyId_items, NULL);
     if (items == NULL) {
         Py_DECREF(args);
         return NULL;
index 7e95af749719d052f1bc35ca0bc903c274ee6d9f..b48dc2dff322a43edebd80b478f1b28bf579cc4c 100644 (file)
@@ -1378,7 +1378,7 @@ time_time(void)
     if (time != NULL) {
         _Py_IDENTIFIER(time);
 
-        result = _PyObject_CallMethodId(time, &PyId_time, "()");
+        result = _PyObject_CallMethodId(time, &PyId_time, NULL);
         Py_DECREF(time);
     }
     return result;
@@ -2703,7 +2703,7 @@ date_isoformat(PyDateTime_Date *self)
 static PyObject *
 date_str(PyDateTime_Date *self)
 {
-    return _PyObject_CallMethodId((PyObject *)self, &PyId_isoformat, "()");
+    return _PyObject_CallMethodId((PyObject *)self, &PyId_isoformat, NULL);
 }
 
 
@@ -2729,7 +2729,7 @@ date_strftime(PyDateTime_Date *self, PyObject *args, PyObject *kw)
                                       &format))
         return NULL;
 
-    tuple = _PyObject_CallMethodId((PyObject *)self, &PyId_timetuple, "()");
+    tuple = _PyObject_CallMethodId((PyObject *)self, &PyId_timetuple, NULL);
     if (tuple == NULL)
         return NULL;
     result = wrap_strftime((PyObject *)self, format, tuple,
@@ -3675,7 +3675,7 @@ time_repr(PyDateTime_Time *self)
 static PyObject *
 time_str(PyDateTime_Time *self)
 {
-    return _PyObject_CallMethodId((PyObject *)self, &PyId_isoformat, "()");
+    return _PyObject_CallMethodId((PyObject *)self, &PyId_isoformat, NULL);
 }
 
 static PyObject *
index a8d414e713ec064a228d9ca7772321510f74b8e7..eae3394533fd3fad1cef381fc3e63043352d7630 100644 (file)
@@ -2873,7 +2873,7 @@ save_dict(PicklerObject *self, PyObject *obj)
         } else {
             _Py_IDENTIFIER(items);
 
-            items = _PyObject_CallMethodId(obj, &PyId_items, "()");
+            items = _PyObject_CallMethodId(obj, &PyId_items, NULL);
             if (items == NULL)
                 goto error;
             iter = PyObject_GetIter(items);
index 6cffb4e8ffadf343685a0fa95050d4622695c5f8..209d4fab1f650c479b17fefc25baa32c0023cead 100644 (file)
@@ -5758,7 +5758,7 @@ static PyObject * \
 FUNCNAME(PyObject *self) \
 { \
     _Py_static_string(id, OPSTR); \
-    return call_method(self, &id, "()"); \
+    return call_method(self, &id, NULL); \
 }
 
 #define SLOT1(FUNCNAME, OPSTR, ARG1TYPE, ARGCODES) \
@@ -5851,7 +5851,7 @@ FUNCNAME(PyObject *self, ARG1TYPE arg1, ARG2TYPE arg2) \
 static Py_ssize_t
 slot_sq_length(PyObject *self)
 {
-    PyObject *res = call_method(self, &PyId___len__, "()");
+    PyObject *res = call_method(self, &PyId___len__, NULL);
     Py_ssize_t len;
 
     if (res == NULL)
@@ -6065,7 +6065,7 @@ static PyObject *
 slot_nb_index(PyObject *self)
 {
     _Py_IDENTIFIER(__index__);
-    return call_method(self, &PyId___index__, "()");
+    return call_method(self, &PyId___index__, NULL);
 }
 
 
@@ -6351,7 +6351,7 @@ static PyObject *
 slot_tp_iternext(PyObject *self)
 {
     _Py_IDENTIFIER(__next__);
-    return call_method(self, &PyId___next__, "()");
+    return call_method(self, &PyId___next__, NULL);
 }
 
 static PyObject *
index 4911f06e44f018cad6bfb50b2b0f2e47d66627fb..37c0ce786488ae067b915db5bb5f03a11bb88095 100644 (file)
@@ -468,7 +468,7 @@ va_build_value(const char *format, va_list va, int flags)
     int n = countformat(f, '\0');
     va_list lva;
 
-        Py_VA_COPY(lva, va);
+    Py_VA_COPY(lva, va);
 
     if (n < 0)
         return NULL;