Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d1584d3

Browse files
committed
Issue #27809: tzinfo_reduce() uses fast call
1 parent f45a561 commit d1584d3

1 file changed

Lines changed: 10 additions & 14 deletions

File tree

Modules/_datetimemodule.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3133,37 +3133,34 @@ tzinfo_fromutc(PyDateTime_TZInfo *self, PyObject *dt)
31333133
static PyObject *
31343134
tzinfo_reduce(PyObject *self)
31353135
{
3136-
PyObject *args, *state, *tmp;
3136+
PyObject *args, *state;
31373137
PyObject *getinitargs, *getstate;
31383138
_Py_IDENTIFIER(__getinitargs__);
31393139
_Py_IDENTIFIER(__getstate__);
31403140

3141-
tmp = PyTuple_New(0);
3142-
if (tmp == NULL)
3143-
return NULL;
3144-
31453141
getinitargs = _PyObject_GetAttrId(self, &PyId___getinitargs__);
31463142
if (getinitargs != NULL) {
3147-
args = PyObject_CallObject(getinitargs, tmp);
3143+
args = _PyObject_CallNoArg(getinitargs);
31483144
Py_DECREF(getinitargs);
31493145
if (args == NULL) {
3150-
Py_DECREF(tmp);
31513146
return NULL;
31523147
}
31533148
}
31543149
else {
31553150
PyErr_Clear();
3156-
args = tmp;
3157-
Py_INCREF(args);
3151+
3152+
args = PyTuple_New(0);
3153+
if (args == NULL) {
3154+
return NULL;
3155+
}
31583156
}
31593157

31603158
getstate = _PyObject_GetAttrId(self, &PyId___getstate__);
31613159
if (getstate != NULL) {
3162-
state = PyObject_CallObject(getstate, tmp);
3160+
state = _PyObject_CallNoArg(getstate);
31633161
Py_DECREF(getstate);
31643162
if (state == NULL) {
31653163
Py_DECREF(args);
3166-
Py_DECREF(tmp);
31673164
return NULL;
31683165
}
31693166
}
@@ -3172,13 +3169,12 @@ tzinfo_reduce(PyObject *self)
31723169
PyErr_Clear();
31733170
state = Py_None;
31743171
dictptr = _PyObject_GetDictPtr(self);
3175-
if (dictptr && *dictptr && PyDict_Size(*dictptr))
3172+
if (dictptr && *dictptr && PyDict_Size(*dictptr)) {
31763173
state = *dictptr;
3174+
}
31773175
Py_INCREF(state);
31783176
}
31793177

3180-
Py_DECREF(tmp);
3181-
31823178
if (state == Py_None) {
31833179
Py_DECREF(state);
31843180
return Py_BuildValue("(ON)", Py_TYPE(self), args);

0 commit comments

Comments
 (0)