[Python-checkins] cpython: build_struct_time() uses Py_BuildValue()
victor.stinner
python-checkins at python.org
Thu Dec 8 20:16:59 EST 2016
https://hg.python.org/cpython/rev/032cbdb596fe
changeset: 105540:032cbdb596fe
user: Victor Stinner <victor.stinner at gmail.com>
date: Fri Dec 09 00:38:16 2016 +0100
summary:
build_struct_time() uses Py_BuildValue()
Issue #28915: Avoid calling _PyObject_CallMethodId() with "(...)" format to
avoid the creation of a temporary tuple: use Py_BuildValue() with
_PyObject_CallMethodIdObjArgs().
files:
Modules/_datetimemodule.c | 31 +++++++++++++++++---------
1 files changed, 20 insertions(+), 11 deletions(-)
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -1385,21 +1385,30 @@
build_struct_time(int y, int m, int d, int hh, int mm, int ss, int dstflag)
{
PyObject *time;
- PyObject *result = NULL;
+ PyObject *result;
+ _Py_IDENTIFIER(struct_time);
+ PyObject *args;
+
time = PyImport_ImportModuleNoBlock("time");
- if (time != NULL) {
- _Py_IDENTIFIER(struct_time);
-
- result = _PyObject_CallMethodId(time, &PyId_struct_time,
- "((iiiiiiiii))",
- y, m, d,
- hh, mm, ss,
- weekday(y, m, d),
- days_before_month(y, m) + d,
- dstflag);
+ if (time == NULL) {
+ return NULL;
+ }
+
+ args = Py_BuildValue("iiiiiiiii",
+ y, m, d,
+ hh, mm, ss,
+ weekday(y, m, d),
+ days_before_month(y, m) + d,
+ dstflag);
+ if (args == NULL) {
Py_DECREF(time);
+ return NULL;
}
+
+ result = _PyObject_CallMethodIdObjArgs(time, &PyId_struct_time,
+ args, NULL);
+ Py_DECREF(time);
return result;
}
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list