mirror of https://github.com/python/cpython
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.
This commit is contained in:
parent
f561634c82
commit
20401deae2
|
@ -987,7 +987,8 @@ call_tzname(PyObject *tzinfo, PyObject *tzinfoarg)
|
||||||
if (tzinfo == Py_None)
|
if (tzinfo == Py_None)
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
|
|
||||||
result = _PyObject_CallMethodId(tzinfo, &PyId_tzname, "O", tzinfoarg);
|
result = _PyObject_CallMethodIdObjArgs(tzinfo, &PyId_tzname,
|
||||||
|
tzinfoarg, NULL);
|
||||||
|
|
||||||
if (result == NULL || result == Py_None)
|
if (result == NULL || result == Py_None)
|
||||||
return result;
|
return result;
|
||||||
|
@ -1343,8 +1344,8 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
|
||||||
goto Done;
|
goto Done;
|
||||||
format = PyUnicode_FromString(PyBytes_AS_STRING(newfmt));
|
format = PyUnicode_FromString(PyBytes_AS_STRING(newfmt));
|
||||||
if (format != NULL) {
|
if (format != NULL) {
|
||||||
result = _PyObject_CallMethodId(time, &PyId_strftime, "OO",
|
result = _PyObject_CallMethodIdObjArgs(time, &PyId_strftime,
|
||||||
format, timetuple, NULL);
|
format, timetuple, NULL);
|
||||||
Py_DECREF(format);
|
Py_DECREF(format);
|
||||||
}
|
}
|
||||||
Py_DECREF(time);
|
Py_DECREF(time);
|
||||||
|
@ -2558,7 +2559,8 @@ date_today(PyObject *cls, PyObject *dummy)
|
||||||
* time.time() delivers; if someone were gonzo about optimization,
|
* time.time() delivers; if someone were gonzo about optimization,
|
||||||
* date.today() could get away with plain C time().
|
* date.today() could get away with plain C time().
|
||||||
*/
|
*/
|
||||||
result = _PyObject_CallMethodId(cls, &PyId_fromtimestamp, "O", time);
|
result = _PyObject_CallMethodIdObjArgs(cls, &PyId_fromtimestamp,
|
||||||
|
time, NULL);
|
||||||
Py_DECREF(time);
|
Py_DECREF(time);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -2746,7 +2748,8 @@ date_format(PyDateTime_Date *self, PyObject *args)
|
||||||
if (PyUnicode_GetLength(format) == 0)
|
if (PyUnicode_GetLength(format) == 0)
|
||||||
return PyObject_Str((PyObject *)self);
|
return PyObject_Str((PyObject *)self);
|
||||||
|
|
||||||
return _PyObject_CallMethodId((PyObject *)self, &PyId_strftime, "O", format);
|
return _PyObject_CallMethodIdObjArgs((PyObject *)self, &PyId_strftime,
|
||||||
|
format, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ISO methods. */
|
/* ISO methods. */
|
||||||
|
@ -4429,8 +4432,8 @@ datetime_strptime(PyObject *cls, PyObject *args)
|
||||||
if (module == NULL)
|
if (module == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return _PyObject_CallMethodId(module, &PyId__strptime_datetime, "OOO",
|
return _PyObject_CallMethodIdObjArgs(module, &PyId__strptime_datetime,
|
||||||
cls, string, format);
|
cls, string, format, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return new datetime from date/datetime and time arguments. */
|
/* Return new datetime from date/datetime and time arguments. */
|
||||||
|
@ -5227,7 +5230,7 @@ datetime_astimezone(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
|
||||||
|
|
||||||
temp = (PyObject *)result;
|
temp = (PyObject *)result;
|
||||||
result = (PyDateTime_DateTime *)
|
result = (PyDateTime_DateTime *)
|
||||||
_PyObject_CallMethodId(tzinfo, &PyId_fromutc, "O", temp);
|
_PyObject_CallMethodIdObjArgs(tzinfo, &PyId_fromutc, temp, NULL);
|
||||||
Py_DECREF(temp);
|
Py_DECREF(temp);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Reference in New Issue