[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master a64fe6f319 3/3: Improve timefns speed on integers
From: |
Paul Eggert |
Subject: |
master a64fe6f319 3/3: Improve timefns speed on integers |
Date: |
Sun, 14 Aug 2022 16:49:40 -0400 (EDT) |
branch: master
commit a64fe6f31987ca4a2c8ac6b96b97c6a440aeb2a2
Author: Paul Eggert <eggert@cs.ucla.edu>
Commit: Paul Eggert <eggert@cs.ucla.edu>
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. */