From 33e9c13e5b866618187da29599544f422ba2beca Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 11 Jul 2024 15:03:50 +0200 Subject: [PATCH] Decode current time directly to timespec * src/timefns.c (decode_time_components): If FASTER_TIMEFNS, when returning the current time and the desired form is struct timespec or time_t, return it directly rather than converting it to struct ticks_hz and then to struct timespec. This can avoid some mpz calculations and/or bignums. (cherry picked from commit e8b3c4cb58ce6e78b9bcfb9146f0ac6ece0d3055) --- src/timefns.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/timefns.c b/src/timefns.c index 6949c83dbcb..ad39d1307cd 100644 --- a/src/timefns.c +++ b/src/timefns.c @@ -884,8 +884,14 @@ decode_time_components (enum timeform form, eassume (false); case TIMEFORM_NIL: - ticks = timespec_ticks (current_timespec ()); - hz = timespec_hz; + { + struct timespec now = current_timespec (); + if (FASTER_TIMEFNS + && (cform == CFORM_TIMESPEC || cform == CFORM_SECS_ONLY)) + return (struct err_time) { .time = { .ts = now } }; + ticks = timespec_ticks (now); + hz = timespec_hz; + } break; default: -- 2.39.2