]> git.eshelyaron.com Git - emacs.git/commitdiff
Streamline time decoding and conversion
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 16 Jun 2022 04:08:03 +0000 (23:08 -0500)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 16 Jun 2022 04:27:08 +0000 (23:27 -0500)
* src/lisp.h (lisp_h_BASE2_EQ, BASE2_EQ): New macros and functions.
* src/timefns.c (tzlookup, Fdecode_time): Use them.
(Ftime_convert): Convert to symbol once, instead of many times.

src/lisp.h
src/timefns.c

index 499bacc3303af422bba6e9f4bb27c12e252fa328..05b0754ff65ed4e42d9b567ed2aec66ea5882818 100644 (file)
@@ -368,6 +368,11 @@ typedef EMACS_INT Lisp_Word;
    ((ok) ? (void) 0 : wrong_type_argument (predicate, x))
 #define lisp_h_CONSP(x) TAGGEDP (x, Lisp_Cons)
 #define lisp_h_BASE_EQ(x, y) (XLI (x) == XLI (y))
+#define lisp_h_BASE2_EQ(x, y)                              \
+  (BASE_EQ (x, y)                                          \
+   || (symbols_with_pos_enabled                                    \
+       && SYMBOL_WITH_POS_P (x)                                    \
+       && BASE_EQ (XSYMBOL_WITH_POS (x)->sym, y)))
 
 /* FIXME: Do we really need to inline the whole thing?
  * What about keeping the part after `symbols_with_pos_enabled` in
@@ -453,6 +458,7 @@ typedef EMACS_INT Lisp_Word;
 # define CHECK_TYPE(ok, predicate, x) lisp_h_CHECK_TYPE (ok, predicate, x)
 # define CONSP(x) lisp_h_CONSP (x)
 # define BASE_EQ(x, y) lisp_h_BASE_EQ (x, y)
+# define BASE2_EQ(x, y) lisp_h_BASE2_EQ (x, y)
 # define FLOATP(x) lisp_h_FLOATP (x)
 # define FIXNUMP(x) lisp_h_FIXNUMP (x)
 # define NILP(x) lisp_h_NILP (x)
@@ -1318,6 +1324,14 @@ INLINE bool
   return lisp_h_BASE_EQ (x, y);
 }
 
+/* Return true if X and Y are the same object, reckoning X to be the
+   same as a bare symbol Y if X is Y with position.  */
+INLINE bool
+(BASE2_EQ) (Lisp_Object x, Lisp_Object y)
+{
+  return lisp_h_BASE2_EQ (x, y);
+}
+
 /* Return true if X and Y are the same object, reckoning a symbol with
    position as being the same as the bare symbol.  */
 INLINE bool
index 6333e302ea509ffee610fe3b368a2ca7e7507292..13a84f6b3cec0b592593c070983c0b2e9ae2e38d 100644 (file)
@@ -212,7 +212,7 @@ tzlookup (Lisp_Object zone, bool settz)
 
   if (NILP (zone))
     return local_tz;
-  else if (EQ (zone, Qt) || BASE_EQ (zone, make_fixnum (0)))
+  else if (BASE_EQ (zone, make_fixnum (0)) || BASE2_EQ (zone, Qt))
     {
       zone_string = "UTC0";
       new_tz = utc_tz;
@@ -221,7 +221,7 @@ tzlookup (Lisp_Object zone, bool settz)
     {
       bool plain_integer = FIXNUMP (zone);
 
-      if (EQ (zone, Qwall))
+      if (BASE2_EQ (zone, Qwall))
        zone_string = 0;
       else if (STRINGP (zone))
        zone_string = SSDATA (ENCODE_SYSTEM (zone));
@@ -729,7 +729,7 @@ decode_time_components (enum timeform form,
 
     case TIMEFORM_TICKS_HZ:
       if (INTEGERP (high)
-         && (!NILP (Fnatnump (low)) && !BASE_EQ (low, make_fixnum (0))))
+         && !NILP (Fnatnump (low)) && !BASE_EQ (low, make_fixnum (0)))
        return decode_ticks_hz (high, low, result, dresult);
       return EINVAL;
 
@@ -1535,7 +1535,7 @@ usage: (decode-time &optional TIME ZONE FORM)  */)
 
   /* Compute SEC from LOCAL_TM.tm_sec and HZ.  */
   Lisp_Object hz = lt.hz, sec;
-  if (BASE_EQ (hz, make_fixnum (1)) || !EQ (form, Qt))
+  if (BASE_EQ (hz, make_fixnum (1)) || !BASE2_EQ (form, Qt))
     sec = make_fixnum (local_tm.tm_sec);
   else
     {
@@ -1748,11 +1748,13 @@ bits, and USEC and PSEC are the microsecond and picosecond counts.  */)
   enum timeform input_form = decode_lisp_time (time, false, &t, 0);
   if (NILP (form))
     form = current_time_list ? Qlist : Qt;
-  if (EQ (form, Qlist))
+  if (symbols_with_pos_enabled && SYMBOL_WITH_POS_P (form))
+    form = SYMBOL_WITH_POS_SYM (form);
+  if (BASE_EQ (form, Qlist))
     return ticks_hz_list4 (t.ticks, t.hz);
-  if (EQ (form, Qinteger))
+  if (BASE_EQ (form, Qinteger))
     return FASTER_TIMEFNS && INTEGERP (time) ? time : lisp_time_seconds (t);
-  if (EQ (form, Qt))
+  if (BASE_EQ (form, Qt))
     form = t.hz;
   if (FASTER_TIMEFNS
       && input_form == TIMEFORM_TICKS_HZ && BASE_EQ (form, XCDR (time)))