aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/timefns.c44
1 files changed, 32 insertions, 12 deletions
diff --git a/src/timefns.c b/src/timefns.c
index cce9dd51ba9..ee43014979e 100644
--- a/src/timefns.c
+++ b/src/timefns.c
@@ -965,6 +965,37 @@ lisp_seconds_argument (Lisp_Object specified_time)
965 return t.tv_sec; 965 return t.tv_sec;
966} 966}
967 967
968/* Return the sum of the Lisp integers A and B.
969 Subtract instead of adding if SUBTRACT.
970 This function is tuned for small B. */
971static Lisp_Object
972lispint_arith (Lisp_Object a, Lisp_Object b, bool subtract)
973{
974 bool mpz_done = false;
975
976 if (FASTER_TIMEFNS && FIXNUMP (b))
977 {
978 if (EQ (b, make_fixnum (0)))
979 return a;
980 if (FIXNUMP (a))
981 return make_int (subtract
982 ? XFIXNUM (a) - XFIXNUM (b)
983 : XFIXNUM (a) + XFIXNUM (b));
984 if (eabs (XFIXNUM (b)) <= ULONG_MAX)
985 {
986 ((XFIXNUM (b) < 0) == subtract ? mpz_add_ui : mpz_sub_ui)
987 (mpz[0], XBIGNUM (a)->value, eabs (XFIXNUM (b)));
988 mpz_done = true;
989 }
990 }
991
992 if (!mpz_done)
993 (subtract ? mpz_sub : mpz_add) (mpz[0],
994 *bignum_integer (&mpz[0], a),
995 *bignum_integer (&mpz[1], b));
996 return make_integer_mpz ();
997}
998
968/* Given Lisp operands A and B, add their values, and return the 999/* Given Lisp operands A and B, add their values, and return the
969 result as a Lisp timestamp that is in (TICKS . HZ) form if either A 1000 result as a Lisp timestamp that is in (TICKS . HZ) form if either A
970 or B are in that form, (HI LO US PS) form otherwise. Subtract 1001 or B are in that form, (HI LO US PS) form otherwise. Subtract
@@ -989,18 +1020,7 @@ time_arith (Lisp_Object a, Lisp_Object b, bool subtract)
989 if (FASTER_TIMEFNS && EQ (ta.hz, tb.hz)) 1020 if (FASTER_TIMEFNS && EQ (ta.hz, tb.hz))
990 { 1021 {
991 hz = ta.hz; 1022 hz = ta.hz;
992 if (FIXNUMP (ta.ticks) && FIXNUMP (tb.ticks)) 1023 ticks = lispint_arith (ta.ticks, tb.ticks, subtract);
993 ticks = make_int (subtract
994 ? XFIXNUM (ta.ticks) - XFIXNUM (tb.ticks)
995 : XFIXNUM (ta.ticks) + XFIXNUM (tb.ticks));
996 else
997 {
998 (subtract ? mpz_sub : mpz_add)
999 (mpz[0],
1000 *bignum_integer (&mpz[0], ta.ticks),
1001 *bignum_integer (&mpz[1], tb.ticks));
1002 ticks = make_integer_mpz ();
1003 }
1004 } 1024 }
1005 else 1025 else
1006 { 1026 {