Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use PyImport_Import(&_Py_ID(_strptime)) without cache
  • Loading branch information
neonene committed Jun 7, 2024
commit 12fad4c4d09908f52f1c1a98344bcd9d55580f9f
1 change: 1 addition & 0 deletions Include/internal/pycore_global_objects_fini_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Include/internal/pycore_global_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(_showwarnmsg)
STRUCT_FOR_ID(_shutdown)
STRUCT_FOR_ID(_slotnames)
STRUCT_FOR_ID(_strptime)
STRUCT_FOR_ID(_strptime_datetime)
STRUCT_FOR_ID(_swappedbytes_)
STRUCT_FOR_ID(_type_)
Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_runtime_init_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Include/internal/pycore_unicodeobject_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 5 additions & 19 deletions Modules/_datetimemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ typedef struct {

/* The interned Unix epoch datetime instance */
PyObject *epoch;

/* _strptime module */
PyObject *strptime;
} datetime_state;

/* The module has a fixed number of static objects, due to being exposed
Expand Down Expand Up @@ -5517,26 +5514,18 @@ datetime_utcfromtimestamp(PyObject *cls, PyObject *args)
static PyObject *
datetime_strptime(PyObject *cls, PyObject *args)
{
PyObject *string, *format;
PyObject *string, *format, *result;

if (!PyArg_ParseTuple(args, "UU:strptime", &string, &format))
return NULL;

PyObject *result = NULL;
PyObject *current_mod = NULL;
datetime_state *st = GET_CURRENT_STATE(current_mod);
PyObject *module = st->strptime;
PyObject *module = PyImport_Import(&_Py_ID(_strptime));
if (module == NULL) {
module = PyImport_ImportModule("_strptime");
Comment thread
neonene marked this conversation as resolved.
if (module == NULL) {
goto exit;
}
st->strptime = module;
return NULL;
}
result = PyObject_CallMethodObjArgs(module, &_Py_ID(_strptime_datetime),
cls, string, format, NULL);
exit:
RELEASE_CURRENT_STATE(st, current_mod);
Py_DECREF(module);
return result;
}

Expand Down Expand Up @@ -7068,7 +7057,6 @@ init_state(datetime_state *st, PyObject *module, PyObject *old_module)
.us_per_week = Py_NewRef(st_old->us_per_week),
.seconds_per_day = Py_NewRef(st_old->seconds_per_day),
.epoch = Py_NewRef(st_old->epoch),
.strptime = st->strptime,
};
return 0;
}
Expand Down Expand Up @@ -7121,8 +7109,7 @@ traverse_state(datetime_state *st, visitproc visit, void *arg)
{
/* heap types */
Py_VISIT(st->isocalendar_date_type);
/* containers */
Py_VISIT(st->strptime);

return 0;
}

Expand All @@ -7138,7 +7125,6 @@ clear_state(datetime_state *st)
Py_CLEAR(st->us_per_week);
Py_CLEAR(st->seconds_per_day);
Py_CLEAR(st->epoch);
Py_CLEAR(st->strptime);
return 0;
}

Expand Down