aboutsummaryrefslogtreecommitdiffstats
path: root/src/timefns.c
diff options
context:
space:
mode:
authorDmitry Gutov2022-08-15 02:22:59 +0300
committerDmitry Gutov2022-08-15 02:22:59 +0300
commitee3a674c7c9e39fe7ff296ce1f9830fc45520de8 (patch)
treee8ba1e7be54314f208454e80e3d31044c913f3eb /src/timefns.c
parentfe0e53d963899a16e0dd1bbc1ba10a6b59f7989e (diff)
parent0a8e88fd83db5398d36064a7f87cff5b57da7284 (diff)
downloademacs-scratch/font_lock_large_files.tar.gz
emacs-scratch/font_lock_large_files.zip
Merge branch 'master' into scratch/font_lock_large_filesscratch/font_lock_large_files
Diffstat (limited to 'src/timefns.c')
-rw-r--r--src/timefns.c71
1 files changed, 47 insertions, 24 deletions
diff --git a/src/timefns.c b/src/timefns.c
index 1112f174763..eed2edf1cc0 100644
--- a/src/timefns.c
+++ b/src/timefns.c
@@ -401,6 +401,10 @@ decode_float_time (double t, struct lisp_time *result)
401 else 401 else
402 { 402 {
403 int scale = double_integer_scale (t); 403 int scale = double_integer_scale (t);
404 /* FIXME: `double_integer_scale` often returns values that are
405 "pessimistic" (i.e. larger than necessary), so 3.5 gets converted
406 to (7881299347898368 . 2251799813685248) rather than (7 . 2).
407 On 64bit systems, this should not matter very much, tho. */
404 eassume (scale < flt_radix_power_size); 408 eassume (scale < flt_radix_power_size);
405 409
406 if (scale < 0) 410 if (scale < 0)
@@ -818,17 +822,6 @@ decode_lisp_time (Lisp_Object specified_time, bool decode_secs_only,
818 822
819 if (NILP (specified_time)) 823 if (NILP (specified_time))
820 form = TIMEFORM_NIL; 824 form = TIMEFORM_NIL;
821 else if (FLOATP (specified_time))
822 {
823 double d = XFLOAT_DATA (specified_time);
824 if (!isfinite (d))
825 time_error (isnan (d) ? EDOM : EOVERFLOW);
826 if (result)
827 decode_float_time (d, result);
828 else
829 *dresult = d;
830 return TIMEFORM_FLOAT;
831 }
832 else if (CONSP (specified_time)) 825 else if (CONSP (specified_time))
833 { 826 {
834 high = XCAR (specified_time); 827 high = XCAR (specified_time);
@@ -868,6 +861,22 @@ decode_lisp_time (Lisp_Object specified_time, bool decode_secs_only,
868 if (! INTEGERP (low)) 861 if (! INTEGERP (low))
869 form = TIMEFORM_INVALID; 862 form = TIMEFORM_INVALID;
870 } 863 }
864 else if (FASTER_TIMEFNS && INTEGERP (specified_time))
865 {
866 decode_ticks_hz (specified_time, make_fixnum (1), result, dresult);
867 return form;
868 }
869 else if (FLOATP (specified_time))
870 {
871 double d = XFLOAT_DATA (specified_time);
872 if (!isfinite (d))
873 time_error (isnan (d) ? EDOM : EOVERFLOW);
874 if (result)
875 decode_float_time (d, result);
876 else
877 *dresult = d;
878 return TIMEFORM_FLOAT;
879 }
871 880
872 int err = decode_time_components (form, high, low, usec, psec, 881 int err = decode_time_components (form, high, low, usec, psec,
873 result, dresult); 882 result, dresult);
@@ -1202,10 +1211,16 @@ time_cmp (Lisp_Object a, Lisp_Object b)
1202 return 0; 1211 return 0;
1203 1212
1204 /* Compare (X . Z) to (Y . Z) quickly if X and Y are fixnums. 1213 /* Compare (X . Z) to (Y . Z) quickly if X and Y are fixnums.
1205 Do not inspect Z, as it is OK to not signal if A and B are invalid. */ 1214 Do not inspect Z, as it is OK to not signal if A and B are invalid.
1206 if (FASTER_TIMEFNS && CONSP (a) && CONSP (b) && BASE_EQ (XCDR (a), XCDR (b)) 1215 Also, compare X to Y quickly if X and Y are fixnums. */
1207 && FIXNUMP (XCAR (a)) && FIXNUMP (XCAR (b))) 1216 if (FASTER_TIMEFNS)
1208 return XFIXNUM (XCAR (a)) - XFIXNUM (XCAR (b)); 1217 {
1218 Lisp_Object x = a, y = b;
1219 if (CONSP (a) && CONSP (b) && BASE_EQ (XCDR (a), XCDR (b)))
1220 x = XCAR (a), y = XCAR (b);
1221 if (FIXNUMP (x) && FIXNUMP (y))
1222 return XFIXNUM (x) - XFIXNUM (y);
1223 }
1209 1224
1210 /* Compare (ATICKS . AZ) to (BTICKS . BHZ) by comparing 1225 /* Compare (ATICKS . AZ) to (BTICKS . BHZ) by comparing
1211 ATICKS * BHZ to BTICKS * AHZ. */ 1226 ATICKS * BHZ to BTICKS * AHZ. */
@@ -1714,21 +1729,29 @@ usage: (encode-time TIME &rest OBSOLESCENT-ARGUMENTS) */)
1714} 1729}
1715 1730
1716DEFUN ("time-convert", Ftime_convert, Stime_convert, 1, 2, 0, 1731DEFUN ("time-convert", Ftime_convert, Stime_convert, 1, 2, 0,
1717 doc: /* Convert TIME value to a Lisp timestamp. 1732 doc: /* Convert TIME value to a Lisp timestamp of the given FORM.
1718With optional FORM, convert to that timestamp form.
1719Truncate the returned value toward minus infinity. 1733Truncate the returned value toward minus infinity.
1720 1734
1721If FORM is nil (the default), return the same form as `current-time'.
1722If FORM is a positive integer, return a pair of integers (TICKS . FORM), 1735If FORM is a positive integer, return a pair of integers (TICKS . FORM),
1723where TICKS is the number of clock ticks and FORM is the clock frequency 1736where TICKS is the number of clock ticks and FORM is the clock frequency
1724in ticks per second. If FORM is t, return (TICKS . PHZ), where 1737in ticks per second.
1725PHZ is a suitable clock frequency in ticks per second. If FORM is 1738
1726`integer', return an integer count of seconds. If FORM is `list', 1739If FORM is t, return (TICKS . PHZ), where PHZ is a suitable clock
1727return an integer list (HIGH LOW USEC PSEC), where HIGH has the most 1740frequency in ticks per second.
1728significant bits of the seconds, LOW has the least significant 16 1741
1729bits, and USEC and PSEC are the microsecond and picosecond counts. */) 1742If FORM is `integer', return an integer count of seconds.
1743
1744If FORM is `list', return an integer list (HIGH LOW USEC PSEC), where
1745HIGH has the most significant bits of the seconds, LOW has the least
1746significant 16 bits, and USEC and PSEC are the microsecond and
1747picosecond counts.
1748
1749If FORM is nil, the behavior depends on `current-time-list',
1750but new code should not rely on it. */)
1730 (Lisp_Object time, Lisp_Object form) 1751 (Lisp_Object time, Lisp_Object form)
1731{ 1752{
1753 /* FIXME: Any reason why we don't offer a `float` output format option as
1754 well, since we accept it as input? */
1732 struct lisp_time t; 1755 struct lisp_time t;
1733 enum timeform input_form = decode_lisp_time (time, false, &t, 0); 1756 enum timeform input_form = decode_lisp_time (time, false, &t, 0);
1734 if (NILP (form)) 1757 if (NILP (form))