Skip to content

Commit 537702d

Browse files
authored
gh-151059: [perf] Use PyObject_CallMethodOneArg in datetime's call_tzinfo_method (#151062)
1 parent a187330 commit 537702d

5 files changed

Lines changed: 12 additions & 5 deletions

File tree

Include/internal/pycore_global_objects_fini_generated.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_global_strings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@ struct _Py_global_strings {
876876
STRUCT_FOR_ID(updates)
877877
STRUCT_FOR_ID(uri)
878878
STRUCT_FOR_ID(usedforsecurity)
879+
STRUCT_FOR_ID(utcoffset)
879880
STRUCT_FOR_ID(value)
880881
STRUCT_FOR_ID(values)
881882
STRUCT_FOR_ID(version)

Include/internal/pycore_runtime_init_generated.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_unicodeobject_generated.h

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_datetimemodule.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,7 +1509,7 @@ get_tzinfo_member(PyObject *self)
15091509
* this returns NULL. Else result is returned.
15101510
*/
15111511
static PyObject *
1512-
call_tzinfo_method(PyObject *tzinfo, const char *name, PyObject *tzinfoarg)
1512+
call_tzinfo_method(PyObject *tzinfo, PyObject *name, PyObject *tzinfoarg)
15131513
{
15141514
PyObject *offset;
15151515

@@ -1519,7 +1519,7 @@ call_tzinfo_method(PyObject *tzinfo, const char *name, PyObject *tzinfoarg)
15191519

15201520
if (tzinfo == Py_None)
15211521
Py_RETURN_NONE;
1522-
offset = PyObject_CallMethod(tzinfo, name, "O", tzinfoarg);
1522+
offset = PyObject_CallMethodOneArg(tzinfo, name, tzinfoarg);
15231523
if (offset == Py_None || offset == NULL)
15241524
return offset;
15251525
if (PyDelta_Check(offset)) {
@@ -1536,7 +1536,7 @@ call_tzinfo_method(PyObject *tzinfo, const char *name, PyObject *tzinfoarg)
15361536
}
15371537
else {
15381538
PyErr_Format(PyExc_TypeError,
1539-
"tzinfo.%s() must return None or "
1539+
"tzinfo.%U() must return None or "
15401540
"timedelta, not '%.200s'",
15411541
name, Py_TYPE(offset)->tp_name);
15421542
Py_DECREF(offset);
@@ -1557,7 +1557,7 @@ call_tzinfo_method(PyObject *tzinfo, const char *name, PyObject *tzinfoarg)
15571557
static PyObject *
15581558
call_utcoffset(PyObject *tzinfo, PyObject *tzinfoarg)
15591559
{
1560-
return call_tzinfo_method(tzinfo, "utcoffset", tzinfoarg);
1560+
return call_tzinfo_method(tzinfo, &_Py_ID(utcoffset), tzinfoarg);
15611561
}
15621562

15631563
/* Call tzinfo.dst(tzinfoarg), and extract an integer from the
@@ -1571,7 +1571,7 @@ call_utcoffset(PyObject *tzinfo, PyObject *tzinfoarg)
15711571
static PyObject *
15721572
call_dst(PyObject *tzinfo, PyObject *tzinfoarg)
15731573
{
1574-
return call_tzinfo_method(tzinfo, "dst", tzinfoarg);
1574+
return call_tzinfo_method(tzinfo, &_Py_ID(dst), tzinfoarg);
15751575
}
15761576

15771577
/* Call tzinfo.tzname(tzinfoarg), and return the result. tzinfo must be

0 commit comments

Comments
 (0)