]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid unnecessary make_float in time arithmetic
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 5 Mar 2022 03:21:38 +0000 (19:21 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 5 Mar 2022 03:29:04 +0000 (19:29 -0800)
* src/timefns.c (float_time): New function.
(time_arith, Ffloat_time): Use it.

src/timefns.c

index f73c69149f77b9e5405ffa7e11f3df18968d1e4e..795a6484ce9eb1fb99de19a6dc939420c56bf884 100644 (file)
@@ -879,6 +879,16 @@ decode_lisp_time (Lisp_Object specified_time, bool decode_secs_only,
   return form;
 }
 
+/* Convert a Lisp timestamp SPECIFIED_TIME to double.
+   Signal an error if unsuccessful.  */
+static double
+float_time (Lisp_Object specified_time)
+{
+  double t;
+  decode_lisp_time (specified_time, false, 0, &t);
+  return t;
+}
+
 /* Convert Z to time_t, returning true if it fits.  */
 static bool
 mpz_time (mpz_t const z, time_t *t)
@@ -1068,7 +1078,7 @@ time_arith (Lisp_Object a, Lisp_Object b, bool subtract)
   if (FLOATP (a) && !isfinite (XFLOAT_DATA (a)))
     {
       double da = XFLOAT_DATA (a);
-      double db = XFLOAT_DATA (Ffloat_time (b));
+      double db = float_time (b);
       return make_float (subtract ? da - db : da + db);
     }
   enum timeform aform, bform;
@@ -1264,9 +1274,7 @@ If precise time stamps are required, use either `encode-time',
 or (if you need time as a string) `format-time-string'.  */)
   (Lisp_Object specified_time)
 {
-  double t;
-  decode_lisp_time (specified_time, false, 0, &t);
-  return make_float (t);
+  return make_float (float_time (specified_time));
 }
 
 /* Write information into buffer S of size MAXSIZE, according to the