From a64fe6f31987ca4a2c8ac6b96b97c6a440aeb2a2 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 14 Aug 2022 13:48:11 -0700 Subject: [PATCH 2/2] Improve timefns speed on integers * src/timefns.c (decode_lisp_time) [FASTER_TIMEFNS]: Speed up when SPECIFIED_TIME is an integer. (time_cmp) [FASTER_TIMEFNS]: Speed up when comparing integers. --- src/timefns.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/timefns.c b/src/timefns.c index b9d9a4ed97..eed2edf1cc 100644 --- a/src/timefns.c +++ b/src/timefns.c @@ -861,6 +861,11 @@ decode_lisp_time (Lisp_Object specified_time, bool decode_secs_only, if (! INTEGERP (low)) form = TIMEFORM_INVALID; } + else if (FASTER_TIMEFNS && INTEGERP (specified_time)) + { + decode_ticks_hz (specified_time, make_fixnum (1), result, dresult); + return form; + } else if (FLOATP (specified_time)) { double d = XFLOAT_DATA (specified_time); @@ -1206,10 +1211,16 @@ time_cmp (Lisp_Object a, Lisp_Object b) return 0; /* Compare (X . Z) to (Y . Z) quickly if X and Y are fixnums. - Do not inspect Z, as it is OK to not signal if A and B are invalid. */ - if (FASTER_TIMEFNS && CONSP (a) && CONSP (b) && BASE_EQ (XCDR (a), XCDR (b)) - && FIXNUMP (XCAR (a)) && FIXNUMP (XCAR (b))) - return XFIXNUM (XCAR (a)) - XFIXNUM (XCAR (b)); + Do not inspect Z, as it is OK to not signal if A and B are invalid. + Also, compare X to Y quickly if X and Y are fixnums. */ + if (FASTER_TIMEFNS) + { + Lisp_Object x = a, y = b; + if (CONSP (a) && CONSP (b) && BASE_EQ (XCDR (a), XCDR (b))) + x = XCAR (a), y = XCAR (b); + if (FIXNUMP (x) && FIXNUMP (y)) + return XFIXNUM (x) - XFIXNUM (y); + } /* Compare (ATICKS . AZ) to (BTICKS . BHZ) by comparing ATICKS * BHZ to BTICKS * AHZ. */ -- 2.34.1