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

Skip to content

Commit 20401de

Browse files
committed
Use _PyObject_CallMethodIdObjArgs() in _datetime
Issue #28915: Replace _PyObject_CallMethodId() with _PyObject_CallMethodIdObjArgs() when the format string was only made of "O" formats, PyObject* arguments. _PyObject_CallMethodIdObjArgs() avoids the creation of a temporary tuple and doesn't have to parse a format string.
1 parent f561634 commit 20401de

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

Modules/_datetimemodule.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,8 @@ call_tzname(PyObject *tzinfo, PyObject *tzinfoarg)
987987
if (tzinfo == Py_None)
988988
Py_RETURN_NONE;
989989

990-
result = _PyObject_CallMethodId(tzinfo, &PyId_tzname, "O", tzinfoarg);
990+
result = _PyObject_CallMethodIdObjArgs(tzinfo, &PyId_tzname,
991+
tzinfoarg, NULL);
991992

992993
if (result == NULL || result == Py_None)
993994
return result;
@@ -1343,8 +1344,8 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
13431344
goto Done;
13441345
format = PyUnicode_FromString(PyBytes_AS_STRING(newfmt));
13451346
if (format != NULL) {
1346-
result = _PyObject_CallMethodId(time, &PyId_strftime, "OO",
1347-
format, timetuple, NULL);
1347+
result = _PyObject_CallMethodIdObjArgs(time, &PyId_strftime,
1348+
format, timetuple, NULL);
13481349
Py_DECREF(format);
13491350
}
13501351
Py_DECREF(time);
@@ -2558,7 +2559,8 @@ date_today(PyObject *cls, PyObject *dummy)
25582559
* time.time() delivers; if someone were gonzo about optimization,
25592560
* date.today() could get away with plain C time().
25602561
*/
2561-
result = _PyObject_CallMethodId(cls, &PyId_fromtimestamp, "O", time);
2562+
result = _PyObject_CallMethodIdObjArgs(cls, &PyId_fromtimestamp,
2563+
time, NULL);
25622564
Py_DECREF(time);
25632565
return result;
25642566
}
@@ -2746,7 +2748,8 @@ date_format(PyDateTime_Date *self, PyObject *args)
27462748
if (PyUnicode_GetLength(format) == 0)
27472749
return PyObject_Str((PyObject *)self);
27482750

2749-
return _PyObject_CallMethodId((PyObject *)self, &PyId_strftime, "O", format);
2751+
return _PyObject_CallMethodIdObjArgs((PyObject *)self, &PyId_strftime,
2752+
format, NULL);
27502753
}
27512754

27522755
/* ISO methods. */
@@ -4429,8 +4432,8 @@ datetime_strptime(PyObject *cls, PyObject *args)
44294432
if (module == NULL)
44304433
return NULL;
44314434
}
4432-
return _PyObject_CallMethodId(module, &PyId__strptime_datetime, "OOO",
4433-
cls, string, format);
4435+
return _PyObject_CallMethodIdObjArgs(module, &PyId__strptime_datetime,
4436+
cls, string, format, NULL);
44344437
}
44354438

44364439
/* Return new datetime from date/datetime and time arguments. */
@@ -5227,7 +5230,7 @@ datetime_astimezone(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
52275230

52285231
temp = (PyObject *)result;
52295232
result = (PyDateTime_DateTime *)
5230-
_PyObject_CallMethodId(tzinfo, &PyId_fromutc, "O", temp);
5233+
_PyObject_CallMethodIdObjArgs(tzinfo, &PyId_fromutc, temp, NULL);
52315234
Py_DECREF(temp);
52325235

52335236
return result;

0 commit comments

Comments
 (0)