[Python-checkins] cpython: Issue #27809: tzinfo_reduce() uses fast call

victor.stinner python-checkins at python.org
Mon Aug 22 18:32:46 EDT 2016


https://hg.python.org/cpython/rev/614dd914c21e
changeset:   102849:614dd914c21e
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Tue Aug 23 00:11:04 2016 +0200
summary:
  Issue #27809: tzinfo_reduce() uses fast call

files:
  Modules/_datetimemodule.c |  24 ++++++++++--------------
  1 files changed, 10 insertions(+), 14 deletions(-)


diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -3133,37 +3133,34 @@
 static PyObject *
 tzinfo_reduce(PyObject *self)
 {
-    PyObject *args, *state, *tmp;
+    PyObject *args, *state;
     PyObject *getinitargs, *getstate;
     _Py_IDENTIFIER(__getinitargs__);
     _Py_IDENTIFIER(__getstate__);
 
-    tmp = PyTuple_New(0);
-    if (tmp == NULL)
-        return NULL;
-
     getinitargs = _PyObject_GetAttrId(self, &PyId___getinitargs__);
     if (getinitargs != NULL) {
-        args = PyObject_CallObject(getinitargs, tmp);
+        args = _PyObject_CallNoArg(getinitargs);
         Py_DECREF(getinitargs);
         if (args == NULL) {
-            Py_DECREF(tmp);
             return NULL;
         }
     }
     else {
         PyErr_Clear();
-        args = tmp;
-        Py_INCREF(args);
+
+        args = PyTuple_New(0);
+        if (args == NULL) {
+            return NULL;
+        }
     }
 
     getstate = _PyObject_GetAttrId(self, &PyId___getstate__);
     if (getstate != NULL) {
-        state = PyObject_CallObject(getstate, tmp);
+        state = _PyObject_CallNoArg(getstate);
         Py_DECREF(getstate);
         if (state == NULL) {
             Py_DECREF(args);
-            Py_DECREF(tmp);
             return NULL;
         }
     }
@@ -3172,13 +3169,12 @@
         PyErr_Clear();
         state = Py_None;
         dictptr = _PyObject_GetDictPtr(self);
-        if (dictptr && *dictptr && PyDict_Size(*dictptr))
+        if (dictptr && *dictptr && PyDict_Size(*dictptr)) {
             state = *dictptr;
+        }
         Py_INCREF(state);
     }
 
-    Py_DECREF(tmp);
-
     if (state == Py_None) {
         Py_DECREF(state);
         return Py_BuildValue("(ON)", Py_TYPE(self), args);

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list