https://github.com/python/cpython/commit/537702d5706e5d3f0e0d1a64c28aab03c9174991
commit: 537702d5706e5d3f0e0d1a64c28aab03c9174991
branch: main
author: Pieter Eendebak <[email protected]>
committer: sobolevn <[email protected]>
date: 2026-06-08T14:11:36+03:00
summary:
gh-151059: [perf] Use `PyObject_CallMethodOneArg` in datetime's
`call_tzinfo_method` (#151062)
files:
M Include/internal/pycore_global_objects_fini_generated.h
M Include/internal/pycore_global_strings.h
M Include/internal/pycore_runtime_init_generated.h
M Include/internal/pycore_unicodeobject_generated.h
M Modules/_datetimemodule.c
diff --git a/Include/internal/pycore_global_objects_fini_generated.h
b/Include/internal/pycore_global_objects_fini_generated.h
index 99a1ffb8ad5229b..1cf766ddb382dd2 100644
--- a/Include/internal/pycore_global_objects_fini_generated.h
+++ b/Include/internal/pycore_global_objects_fini_generated.h
@@ -2153,6 +2153,7 @@ _PyStaticObjects_CheckRefcnt(PyInterpreterState *interp) {
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(updates));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(uri));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(usedforsecurity));
+ _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(utcoffset));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(value));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(values));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(version));
diff --git a/Include/internal/pycore_global_strings.h
b/Include/internal/pycore_global_strings.h
index d5818402a508cb9..017d62e002fdff9 100644
--- a/Include/internal/pycore_global_strings.h
+++ b/Include/internal/pycore_global_strings.h
@@ -876,6 +876,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(updates)
STRUCT_FOR_ID(uri)
STRUCT_FOR_ID(usedforsecurity)
+ STRUCT_FOR_ID(utcoffset)
STRUCT_FOR_ID(value)
STRUCT_FOR_ID(values)
STRUCT_FOR_ID(version)
diff --git a/Include/internal/pycore_runtime_init_generated.h
b/Include/internal/pycore_runtime_init_generated.h
index 8227f3fa9eedcf5..75273243ef6df06 100644
--- a/Include/internal/pycore_runtime_init_generated.h
+++ b/Include/internal/pycore_runtime_init_generated.h
@@ -2151,6 +2151,7 @@ extern "C" {
INIT_ID(updates), \
INIT_ID(uri), \
INIT_ID(usedforsecurity), \
+ INIT_ID(utcoffset), \
INIT_ID(value), \
INIT_ID(values), \
INIT_ID(version), \
diff --git a/Include/internal/pycore_unicodeobject_generated.h
b/Include/internal/pycore_unicodeobject_generated.h
index cb731e9a6888781..164d9d412ef5e95 100644
--- a/Include/internal/pycore_unicodeobject_generated.h
+++ b/Include/internal/pycore_unicodeobject_generated.h
@@ -3284,6 +3284,10 @@ _PyUnicode_InitStaticStrings(PyInterpreterState *interp)
{
_PyUnicode_InternStatic(interp, &string);
assert(_PyUnicode_CheckConsistency(string, 1));
assert(PyUnicode_GET_LENGTH(string) != 1);
+ string = &_Py_ID(utcoffset);
+ _PyUnicode_InternStatic(interp, &string);
+ assert(_PyUnicode_CheckConsistency(string, 1));
+ assert(PyUnicode_GET_LENGTH(string) != 1);
string = &_Py_ID(value);
_PyUnicode_InternStatic(interp, &string);
assert(_PyUnicode_CheckConsistency(string, 1));
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index 59af7afcfcc644e..30317ea823ff7ee 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -1509,7 +1509,7 @@ get_tzinfo_member(PyObject *self)
* this returns NULL. Else result is returned.
*/
static PyObject *
-call_tzinfo_method(PyObject *tzinfo, const char *name, PyObject *tzinfoarg)
+call_tzinfo_method(PyObject *tzinfo, PyObject *name, PyObject *tzinfoarg)
{
PyObject *offset;
@@ -1519,7 +1519,7 @@ call_tzinfo_method(PyObject *tzinfo, const char *name,
PyObject *tzinfoarg)
if (tzinfo == Py_None)
Py_RETURN_NONE;
- offset = PyObject_CallMethod(tzinfo, name, "O", tzinfoarg);
+ offset = PyObject_CallMethodOneArg(tzinfo, name, tzinfoarg);
if (offset == Py_None || offset == NULL)
return offset;
if (PyDelta_Check(offset)) {
@@ -1536,7 +1536,7 @@ call_tzinfo_method(PyObject *tzinfo, const char *name,
PyObject *tzinfoarg)
}
else {
PyErr_Format(PyExc_TypeError,
- "tzinfo.%s() must return None or "
+ "tzinfo.%U() must return None or "
"timedelta, not '%.200s'",
name, Py_TYPE(offset)->tp_name);
Py_DECREF(offset);
@@ -1557,7 +1557,7 @@ call_tzinfo_method(PyObject *tzinfo, const char *name,
PyObject *tzinfoarg)
static PyObject *
call_utcoffset(PyObject *tzinfo, PyObject *tzinfoarg)
{
- return call_tzinfo_method(tzinfo, "utcoffset", tzinfoarg);
+ return call_tzinfo_method(tzinfo, &_Py_ID(utcoffset), tzinfoarg);
}
/* Call tzinfo.dst(tzinfoarg), and extract an integer from the
@@ -1571,7 +1571,7 @@ call_utcoffset(PyObject *tzinfo, PyObject *tzinfoarg)
static PyObject *
call_dst(PyObject *tzinfo, PyObject *tzinfoarg)
{
- return call_tzinfo_method(tzinfo, "dst", tzinfoarg);
+ return call_tzinfo_method(tzinfo, &_Py_ID(dst), tzinfoarg);
}
/* Call tzinfo.tzname(tzinfoarg), and return the result. tzinfo must be
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]