[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 914cf4b91b 04/16: Make time arithmetic more like comparison
From: |
Paul Eggert |
Subject: |
master 914cf4b91b 04/16: Make time arithmetic more like comparison |
Date: |
Mon, 1 Aug 2022 04:17:27 -0400 (EDT) |
branch: master
commit 914cf4b91ba8bdf63cd10a66f970c396329beeab
Author: Paul Eggert <eggert@cs.ucla.edu>
Commit: Paul Eggert <eggert@cs.ucla.edu>
Make time arithmetic more like comparison
Since time comparison says X == X, have time arithmetic behave
similarly for X - X. This should also be a bit faster due to not
having to test for floats and NaNs.
* src/timefns.c (time_arith, time_cmp):
Simplify by not worrying about NaNs, which are not time values.
(time_arith): Simplify by not worrying about subtracting nil from
nil; the caller now handles this.
(Ftime_subtract): Handle subtracting X from X specially.
---
src/timefns.c | 44 +++++++++++---------------------------------
1 file changed, 11 insertions(+), 33 deletions(-)
diff --git a/src/timefns.c b/src/timefns.c
index 25bfda513c..c8becac863 100644
--- a/src/timefns.c
+++ b/src/timefns.c
@@ -1074,27 +1074,9 @@ lispint_arith (Lisp_Object a, Lisp_Object b, bool
subtract)
static Lisp_Object
time_arith (Lisp_Object a, Lisp_Object b, bool subtract)
{
- if (FLOATP (a) && !isfinite (XFLOAT_DATA (a)))
- {
- double da = XFLOAT_DATA (a);
- double db = float_time (b);
- return make_float (subtract ? da - db : da + db);
- }
enum timeform aform, bform;
struct lisp_time ta = lisp_time_struct (a, &aform);
-
- if (FLOATP (b) && !isfinite (XFLOAT_DATA (b)))
- return subtract ? make_float (-XFLOAT_DATA (b)) : b;
-
- /* Subtract nil from nil correctly, and handle other eq values
- quicker while we're at it. Compare here rather than earlier, to
- handle NaNs and check formats. */
- struct lisp_time tb;
- if (BASE_EQ (a, b))
- bform = aform, tb = ta;
- else
- tb = lisp_time_struct (b, &bform);
-
+ struct lisp_time tb = lisp_time_struct (b, &bform);
Lisp_Object ticks, hz;
if (FASTER_TIMEFNS && BASE_EQ (ta.hz, tb.hz))
@@ -1201,27 +1183,23 @@ See `format-time-string' for the various forms of a
time value.
For example, nil stands for the current time. */)
(Lisp_Object a, Lisp_Object b)
{
+ /* Subtract nil from nil correctly, and handle other eq values
+ quicker while we're at it. This means (time-subtract X X) does
+ not signal an error if X is not a valid time value, but that's OK. */
+ if (BASE_EQ (a, b))
+ return timespec_to_lisp ((struct timespec) {0});
+
return time_arith (a, b, true);
}
-/* Return negative, 0, positive if a < b, a == b, a > b respectively.
- Return positive if either a or b is a NaN; this is good enough
- for the current callers. */
+/* Return negative, 0, positive if A < B, A == B, A > B respectively.
+ A and B should be Lisp time values. */
static int
time_cmp (Lisp_Object a, Lisp_Object b)
{
- if ((FLOATP (a) && !isfinite (XFLOAT_DATA (a)))
- || (FLOATP (b) && !isfinite (XFLOAT_DATA (b))))
- {
- double da = FLOATP (a) ? XFLOAT_DATA (a) : 0;
- double db = FLOATP (b) ? XFLOAT_DATA (b) : 0;
- return da < db ? -1 : da != db;
- }
-
/* Compare nil to nil correctly, and handle other eq values quicker
- while we're at it. Compare here rather than earlier, to handle
- NaNs. This means (time-equal-p X X) does not signal an error if
- X is not a valid time value, but that's OK. */
+ while we're at it. This means (time-equal-p X X) does not signal
+ an error if X is not a valid time value, but that's OK. */
if (BASE_EQ (a, b))
return 0;
- master updated (ee0ce18662 -> bec8474a45), Paul Eggert, 2022/08/01
- master 24e1123241 06/16: Improve time-equal-p etc. performance, Paul Eggert, 2022/08/01
- master 914cf4b91b 04/16: Make time arithmetic more like comparison,
Paul Eggert <=
- 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, 2022/08/01