Skip to content

Commit 20f3033

Browse files
committed
pythongh-112919: Speed-up datetime, date and time.replace() (pythonGH-112921)
Use argument clinic and call new_* functions directly. This speeds up these functions 6x to 7.5x when calling with keyword arguments. (cherry picked from commit 1f515e8)
1 parent 5ec271d commit 20f3033

7 files changed

Lines changed: 473 additions & 93 deletions

Include/internal/pycore_global_objects_fini_generated.h

Lines changed: 8 additions & 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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ struct _Py_global_strings {
360360
STRUCT_FOR_ID(d)
361361
STRUCT_FOR_ID(data)
362362
STRUCT_FOR_ID(database)
363+
STRUCT_FOR_ID(day)
363364
STRUCT_FOR_ID(decode)
364365
STRUCT_FOR_ID(decoder)
365366
STRUCT_FOR_ID(default)
@@ -429,6 +430,7 @@ struct _Py_global_strings {
429430
STRUCT_FOR_ID(fix_imports)
430431
STRUCT_FOR_ID(flags)
431432
STRUCT_FOR_ID(flush)
433+
STRUCT_FOR_ID(fold)
432434
STRUCT_FOR_ID(follow_symlinks)
433435
STRUCT_FOR_ID(format)
434436
STRUCT_FOR_ID(frequency)
@@ -458,6 +460,7 @@ struct _Py_global_strings {
458460
STRUCT_FOR_ID(headers)
459461
STRUCT_FOR_ID(hi)
460462
STRUCT_FOR_ID(hook)
463+
STRUCT_FOR_ID(hour)
461464
STRUCT_FOR_ID(id)
462465
STRUCT_FOR_ID(ident)
463466
STRUCT_FOR_ID(ignore)
@@ -538,11 +541,14 @@ struct _Py_global_strings {
538541
STRUCT_FOR_ID(metaclass)
539542
STRUCT_FOR_ID(metadata)
540543
STRUCT_FOR_ID(method)
544+
STRUCT_FOR_ID(microsecond)
545+
STRUCT_FOR_ID(minute)
541546
STRUCT_FOR_ID(mod)
542547
STRUCT_FOR_ID(mode)
543548
STRUCT_FOR_ID(module)
544549
STRUCT_FOR_ID(module_globals)
545550
STRUCT_FOR_ID(modules)
551+
STRUCT_FOR_ID(month)
546552
STRUCT_FOR_ID(mro)
547553
STRUCT_FOR_ID(msg)
548554
STRUCT_FOR_ID(mycmp)
@@ -647,6 +653,7 @@ struct _Py_global_strings {
647653
STRUCT_FOR_ID(salt)
648654
STRUCT_FOR_ID(sched_priority)
649655
STRUCT_FOR_ID(scheduler)
656+
STRUCT_FOR_ID(second)
650657
STRUCT_FOR_ID(seek)
651658
STRUCT_FOR_ID(seekable)
652659
STRUCT_FOR_ID(selectors)
@@ -724,6 +731,7 @@ struct _Py_global_strings {
724731
STRUCT_FOR_ID(type)
725732
STRUCT_FOR_ID(type_params)
726733
STRUCT_FOR_ID(tz)
734+
STRUCT_FOR_ID(tzinfo)
727735
STRUCT_FOR_ID(tzname)
728736
STRUCT_FOR_ID(uid)
729737
STRUCT_FOR_ID(unlink)

Include/internal/pycore_runtime_init_generated.h

Lines changed: 8 additions & 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: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
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)