[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 0a4477415c 05/16: Improve float-time etc. performance
From: |
Paul Eggert |
Subject: |
master 0a4477415c 05/16: Improve float-time etc. performance |
Date: |
Mon, 1 Aug 2022 04:17:27 -0400 (EDT) |
branch: master
commit 0a4477415c9df7d2cce8906155caadaa092b167e
Author: Paul Eggert <eggert@cs.ucla.edu>
Commit: Paul Eggert <eggert@cs.ucla.edu>
Improve float-time etc. performance
* src/timefns.c (decode_float_time): Assume T is finite.
All callers changed.
(decode_time_components): Assume FORM is not TIMEFORM_FLOAT.
All callers changed.
(decode_lisp_time): If the specified time is a float,
signal an error if it is not finite.
(Ffloat_time): If the specified time is a float,
simply return it.
---
src/timefns.c | 39 +++++++++++++++++++--------------------
1 file changed, 19 insertions(+), 20 deletions(-)
diff --git a/src/timefns.c b/src/timefns.c
index c8becac863..078e1f40fb 100644
--- a/src/timefns.c
+++ b/src/timefns.c
@@ -387,9 +387,9 @@ enum { flt_radix_power_size = DBL_MANT_DIG - DBL_MIN_EXP +
1 };
equals FLT_RADIX**P. */
static Lisp_Object flt_radix_power;
-/* Convert T into an Emacs time *RESULT, truncating toward minus infinity.
- Return zero if successful, an error number otherwise. */
-static int
+/* Convert the finite number T into an Emacs time *RESULT, truncating
+ toward minus infinity. Signal an error if unsuccessful. */
+static void
decode_float_time (double t, struct lisp_time *result)
{
Lisp_Object ticks, hz;
@@ -401,6 +401,7 @@ decode_float_time (double t, struct lisp_time *result)
else
{
int scale = double_integer_scale (t);
+ eassume (scale < flt_radix_power_size);
if (scale < 0)
{
@@ -412,8 +413,6 @@ decode_float_time (double t, struct lisp_time *result)
which is typically better than signaling overflow. */
scale = 0;
}
- else if (flt_radix_power_size <= scale)
- return isnan (t) ? EDOM : EOVERFLOW;
/* Compute TICKS, HZ such that TICKS / HZ exactly equals T, where HZ is
T's frequency or 1, whichever is greater. Here, “frequency” means
@@ -431,7 +430,6 @@ decode_float_time (double t, struct lisp_time *result)
}
result->ticks = ticks;
result->hz = hz;
- return 0;
}
/* Make a 4-element timestamp (HI LO US PS) from TICKS and HZ.
@@ -705,7 +703,7 @@ enum timeform
TIMEFORM_TICKS_HZ /* fractional time: HI is ticks, LO is ticks per second */
};
-/* From the valid form FORM and the time components HIGH, LOW, USEC
+/* From the non-float form FORM and the time components HIGH, LOW, USEC
and PSEC, generate the corresponding time value. If LOW is
floating point, the other components should be zero and FORM should
not be TIMEFORM_TICKS_HZ.
@@ -734,16 +732,7 @@ decode_time_components (enum timeform form,
return EINVAL;
case TIMEFORM_FLOAT:
- {
- double t = XFLOAT_DATA (low);
- if (result)
- return decode_float_time (t, result);
- else
- {
- *dresult = t;
- return 0;
- }
- }
+ eassume (false);
case TIMEFORM_NIL:
return decode_ticks_hz (timespec_ticks (current_timespec ()),
@@ -830,7 +819,16 @@ decode_lisp_time (Lisp_Object specified_time, bool
decode_secs_only,
if (NILP (specified_time))
form = TIMEFORM_NIL;
else if (FLOATP (specified_time))
- form = TIMEFORM_FLOAT;
+ {
+ double d = XFLOAT_DATA (specified_time);
+ if (!isfinite (d))
+ time_error (isnan (d) ? EDOM : EOVERFLOW);
+ if (result)
+ decode_float_time (d, result);
+ else
+ *dresult = d;
+ return TIMEFORM_FLOAT;
+ }
else if (CONSP (specified_time))
{
high = XCAR (specified_time);
@@ -878,7 +876,7 @@ decode_lisp_time (Lisp_Object specified_time, bool
decode_secs_only,
return form;
}
-/* Convert a Lisp timestamp SPECIFIED_TIME to double.
+/* Convert a non-float Lisp timestamp SPECIFIED_TIME to double.
Signal an error if unsuccessful. */
double
float_time (Lisp_Object specified_time)
@@ -1253,7 +1251,8 @@ 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)
{
- return make_float (float_time (specified_time));
+ return (FLOATP (specified_time) ? specified_time
+ : make_float (float_time (specified_time)));
}
/* Write information into buffer S of size MAXSIZE, according to the
- master 914cf4b91b 04/16: Make time arithmetic more like comparison, (continued)
- master 914cf4b91b 04/16: Make time arithmetic more like comparison, Paul Eggert, 2022/08/01
- master afa67ed6f2 08/16: Fix year-285428751 bug in hanoi-unix-64, Paul Eggert, 2022/08/01
- master 353413a76b 10/16: * lisp/vc/vc.el: Remove stray comment hyphen., Paul Eggert, 2022/08/01
- master 932c0bc1fc 01/16: Tune blv_found, Paul Eggert, 2022/08/01
- master d6c054a007 09/16: Fix "cons up a storm" issue in type-break, Paul Eggert, 2022/08/01
- master a51863f73d 12/16: Simplify a few timestamps, Paul Eggert, 2022/08/01
- master d634cb0954 11/16: Omit some (current-time) calls, Paul Eggert, 2022/08/01
- master 2cd204d8bb 13/16: Prefer ‘time-equal-p’ to ‘equal’ on timestamps, Paul Eggert, 2022/08/01
- master 72c3efd7d0 15/16: Fix time comparison in primitive-undo, Paul Eggert, 2022/08/01
- master bec8474a45 16/16: Improve GCC pacification in xterm.c, Paul Eggert, 2022/08/01
- master 0a4477415c 05/16: Improve float-time etc. performance,
Paul Eggert <=
- master 9d4633e934 02/16: (time-equal-p nil X) returns nil, Paul Eggert, 2022/08/01
- master e3b6242938 03/16: Fix get-internal-runtime precision, Paul Eggert, 2022/08/01
- master 2fd2008e67 07/16: * src/timefns.c (Ffloat_time): Fix doc string., Paul Eggert, 2022/08/01
- master 4d896c0977 14/16: Use list-form timestamps in .nnmh-articles, Paul Eggert, 2022/08/01