Skip to content

Commit 1f515e8

Browse files
authored
gh-112919: Speed-up datetime, date and time.replace() (GH-112921)
Use argument clinic and call new_* functions directly. This speeds up these functions 6x to 7.5x when calling with keyword arguments.
1 parent 4287e86 commit 1f515e8

7 files changed

+476
-96
lines changed

Include/internal/pycore_global_objects_fini_generated.h

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_global_strings.h

+8
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ struct _Py_global_strings {
365365
STRUCT_FOR_ID(d)
366366
STRUCT_FOR_ID(data)
367367
STRUCT_FOR_ID(database)
368+
STRUCT_FOR_ID(day)
368369
STRUCT_FOR_ID(decode)
369370
STRUCT_FOR_ID(decoder)
370371
STRUCT_FOR_ID(default)
@@ -434,6 +435,7 @@ struct _Py_global_strings {
434435
STRUCT_FOR_ID(fix_imports)
435436
STRUCT_FOR_ID(flags)
436437
STRUCT_FOR_ID(flush)
438+
STRUCT_FOR_ID(fold)
437439
STRUCT_FOR_ID(follow_symlinks)
438440
STRUCT_FOR_ID(format)
439441
STRUCT_FOR_ID(from_param)
@@ -464,6 +466,7 @@ struct _Py_global_strings {
464466
STRUCT_FOR_ID(headers)
465467
STRUCT_FOR_ID(hi)
466468
STRUCT_FOR_ID(hook)
469+
STRUCT_FOR_ID(hour)
467470
STRUCT_FOR_ID(id)
468471
STRUCT_FOR_ID(ident)
469472
STRUCT_FOR_ID(identity_hint)
@@ -548,11 +551,14 @@ struct _Py_global_strings {
548551
STRUCT_FOR_ID(metaclass)
549552
STRUCT_FOR_ID(metadata)
550553
STRUCT_FOR_ID(method)
554+
STRUCT_FOR_ID(microsecond)
555+
STRUCT_FOR_ID(minute)
551556
STRUCT_FOR_ID(mod)
552557
STRUCT_FOR_ID(mode)
553558
STRUCT_FOR_ID(module)
554559
STRUCT_FOR_ID(module_globals)
555560
STRUCT_FOR_ID(modules)
561+
STRUCT_FOR_ID(month)
556562
STRUCT_FOR_ID(mro)
557563
STRUCT_FOR_ID(msg)
558564
STRUCT_FOR_ID(mycmp)
@@ -657,6 +663,7 @@ struct _Py_global_strings {
657663
STRUCT_FOR_ID(salt)
658664
STRUCT_FOR_ID(sched_priority)
659665
STRUCT_FOR_ID(scheduler)
666+
STRUCT_FOR_ID(second)
660667
STRUCT_FOR_ID(seek)
661668
STRUCT_FOR_ID(seekable)
662669
STRUCT_FOR_ID(selectors)
@@ -733,6 +740,7 @@ struct _Py_global_strings {
733740
STRUCT_FOR_ID(type)
734741
STRUCT_FOR_ID(type_params)
735742
STRUCT_FOR_ID(tz)
743+
STRUCT_FOR_ID(tzinfo)
736744
STRUCT_FOR_ID(tzname)
737745
STRUCT_FOR_ID(uid)
738746
STRUCT_FOR_ID(unlink)

Include/internal/pycore_runtime_init_generated.h

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_unicodeobject_generated.h

+24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Speed-up :func:`datetime.datetime.replace`, :func:`datetime.date.replace` and
2+
:func:`datetime.time.replace`.

0 commit comments

Comments
 (0)