diff options
| author | Paul Eggert | 2017-10-22 01:04:36 -0700 |
|---|---|---|
| committer | Paul Eggert | 2017-10-22 01:07:32 -0700 |
| commit | 3aee7be62eaf8caef6f2fab31bee79674b3abbb7 (patch) | |
| tree | 29226a5776f2ded9966138b98b5cef15b50ce463 | |
| parent | 2bfa42855bf0278497f2e4540eac2086dab254c3 (diff) | |
| download | emacs-3aee7be62eaf8caef6f2fab31bee79674b3abbb7.tar.gz emacs-3aee7be62eaf8caef6f2fab31bee79674b3abbb7.zip | |
Avoid unnecessary rounding errors in timestamps
Avoid the rounding errors of float-time when it’s easy. E.g.,
replace (< (float-time a) (float-time b)) with (time-less-p a b).
* lisp/desktop.el (desktop-save):
* lisp/ecomplete.el (ecomplete-add-item):
* lisp/epg.el (epg-wait-for-completion):
* lisp/files.el (dir-locals-find-file, dir-locals-read-from-dir):
* lisp/image-dired.el (image-dired-get-thumbnail-image)
(image-dired-create-thumb-1):
* lisp/info.el (info-insert-file-contents):
* lisp/ls-lisp.el (ls-lisp-format-time):
* lisp/net/ange-ftp.el (ange-ftp-file-newer-than-file-p)
(ange-ftp-verify-visited-file-modtime):
* lisp/net/rcirc.el (rcirc-ctcp-sender-PING):
* lisp/textmodes/remember.el (remember-store-in-mailbox):
* lisp/url/url-cookie.el (url-cookie-expired-p):
Bypass float-time to avoid rounding errors.
* lisp/files.el (dir-locals-find-file):
| -rw-r--r-- | lisp/desktop.el | 3 | ||||
| -rw-r--r-- | lisp/ecomplete.el | 2 | ||||
| -rw-r--r-- | lisp/epg.el | 5 | ||||
| -rw-r--r-- | lisp/files.el | 31 | ||||
| -rw-r--r-- | lisp/image-dired.el | 15 | ||||
| -rw-r--r-- | lisp/info.el | 2 | ||||
| -rw-r--r-- | lisp/ls-lisp.el | 5 | ||||
| -rw-r--r-- | lisp/net/ange-ftp.el | 4 | ||||
| -rw-r--r-- | lisp/net/rcirc.el | 2 | ||||
| -rw-r--r-- | lisp/textmodes/remember.el | 2 | ||||
| -rw-r--r-- | lisp/url/url-cookie.el | 2 |
11 files changed, 35 insertions, 38 deletions
diff --git a/lisp/desktop.el b/lisp/desktop.el index 73228ce040b..52cdbaf849d 100644 --- a/lisp/desktop.el +++ b/lisp/desktop.el | |||
| @@ -1046,7 +1046,8 @@ without further confirmation." | |||
| 1046 | (or (not new-modtime) ; nothing to overwrite | 1046 | (or (not new-modtime) ; nothing to overwrite |
| 1047 | (equal desktop-file-modtime new-modtime) | 1047 | (equal desktop-file-modtime new-modtime) |
| 1048 | (yes-or-no-p (if desktop-file-modtime | 1048 | (yes-or-no-p (if desktop-file-modtime |
| 1049 | (if (> (float-time new-modtime) (float-time desktop-file-modtime)) | 1049 | (if (time-less-p desktop-file-modtime |
| 1050 | new-modtime) | ||
| 1050 | "Desktop file is more recent than the one loaded. Save anyway? " | 1051 | "Desktop file is more recent than the one loaded. Save anyway? " |
| 1051 | "Desktop file isn't the one loaded. Overwrite it? ") | 1052 | "Desktop file isn't the one loaded. Overwrite it? ") |
| 1052 | "Current desktop was not loaded from a file. Overwrite this desktop file? ")) | 1053 | "Current desktop was not loaded from a file. Overwrite this desktop file? ")) |
diff --git a/lisp/ecomplete.el b/lisp/ecomplete.el index ed23d9f5cc2..014b4b21122 100644 --- a/lisp/ecomplete.el +++ b/lisp/ecomplete.el | |||
| @@ -55,7 +55,7 @@ | |||
| 55 | 55 | ||
| 56 | (defun ecomplete-add-item (type key text) | 56 | (defun ecomplete-add-item (type key text) |
| 57 | (let ((elems (assq type ecomplete-database)) | 57 | (let ((elems (assq type ecomplete-database)) |
| 58 | (now (string-to-number (format "%.0f" (float-time)))) | 58 | (now (string-to-number (format-time-string "%s"))) |
| 59 | entry) | 59 | entry) |
| 60 | (unless elems | 60 | (unless elems |
| 61 | (push (setq elems (list type)) ecomplete-database)) | 61 | (push (setq elems (list type)) ecomplete-database)) |
diff --git a/lisp/epg.el b/lisp/epg.el index 407b0f5d5d3..fee6ad75119 100644 --- a/lisp/epg.el +++ b/lisp/epg.el | |||
| @@ -757,9 +757,8 @@ callback data (if any)." | |||
| 757 | ;; Restore Emacs frame on text terminal, when pinentry-curses has terminated. | 757 | ;; Restore Emacs frame on text terminal, when pinentry-curses has terminated. |
| 758 | (if (with-current-buffer (process-buffer (epg-context-process context)) | 758 | (if (with-current-buffer (process-buffer (epg-context-process context)) |
| 759 | (and epg-agent-file | 759 | (and epg-agent-file |
| 760 | (> (float-time (or (nth 5 (file-attributes epg-agent-file)) | 760 | (time-less-p epg-agent-mtime |
| 761 | '(0 0 0 0))) | 761 | (or (nth 5 (file-attributes epg-agent-file)) 0)))) |
| 762 | (float-time epg-agent-mtime)))) | ||
| 763 | (redraw-frame)) | 762 | (redraw-frame)) |
| 764 | (epg-context-set-result-for | 763 | (epg-context-set-result-for |
| 765 | context 'error | 764 | context 'error |
diff --git a/lisp/files.el b/lisp/files.el index 211457ac7d7..9d46d5f85aa 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -3947,11 +3947,12 @@ This function returns either: | |||
| 3947 | ;; The entry MTIME should match the most recent | 3947 | ;; The entry MTIME should match the most recent |
| 3948 | ;; MTIME among matching files. | 3948 | ;; MTIME among matching files. |
| 3949 | (and cached-files | 3949 | (and cached-files |
| 3950 | (= (float-time (nth 2 dir-elt)) | 3950 | (equal (nth 2 dir-elt) |
| 3951 | (apply #'max (mapcar (lambda (f) | 3951 | (let ((latest 0)) |
| 3952 | (float-time | 3952 | (dolist (f cached-files latest) |
| 3953 | (nth 5 (file-attributes f)))) | 3953 | (let ((f-time (nth 5 (file-attributes f)))) |
| 3954 | cached-files)))))) | 3954 | (if (time-less-p latest f-time) |
| 3955 | (setq latest f-time))))))))) | ||
| 3955 | ;; This cache entry is OK. | 3956 | ;; This cache entry is OK. |
| 3956 | dir-elt | 3957 | dir-elt |
| 3957 | ;; This cache entry is invalid; clear it. | 3958 | ;; This cache entry is invalid; clear it. |
| @@ -3973,10 +3974,15 @@ Return the new class name, which is a symbol named DIR." | |||
| 3973 | (let* ((class-name (intern dir)) | 3974 | (let* ((class-name (intern dir)) |
| 3974 | (files (dir-locals--all-files dir)) | 3975 | (files (dir-locals--all-files dir)) |
| 3975 | (read-circle nil) | 3976 | (read-circle nil) |
| 3976 | (success nil) | 3977 | ;; If there was a problem, use the values we could get but |
| 3978 | ;; don't let the cache prevent future reads. | ||
| 3979 | (latest 0) (success 0) | ||
| 3977 | (variables)) | 3980 | (variables)) |
| 3978 | (with-demoted-errors "Error reading dir-locals: %S" | 3981 | (with-demoted-errors "Error reading dir-locals: %S" |
| 3979 | (dolist (file files) | 3982 | (dolist (file files) |
| 3983 | (let ((file-time (nth 5 (file-attributes file)))) | ||
| 3984 | (if (time-less-p latest file-time) | ||
| 3985 | (setq latest file-time))) | ||
| 3980 | (with-temp-buffer | 3986 | (with-temp-buffer |
| 3981 | (insert-file-contents file) | 3987 | (insert-file-contents file) |
| 3982 | (condition-case-unless-debug nil | 3988 | (condition-case-unless-debug nil |
| @@ -3985,18 +3991,9 @@ Return the new class name, which is a symbol named DIR." | |||
| 3985 | variables | 3991 | variables |
| 3986 | (read (current-buffer)))) | 3992 | (read (current-buffer)))) |
| 3987 | (end-of-file nil)))) | 3993 | (end-of-file nil)))) |
| 3988 | (setq success t)) | 3994 | (setq success latest)) |
| 3989 | (dir-locals-set-class-variables class-name variables) | 3995 | (dir-locals-set-class-variables class-name variables) |
| 3990 | (dir-locals-set-directory-class | 3996 | (dir-locals-set-directory-class dir class-name success) |
| 3991 | dir class-name | ||
| 3992 | (seconds-to-time | ||
| 3993 | (if success | ||
| 3994 | (apply #'max (mapcar (lambda (file) | ||
| 3995 | (float-time (nth 5 (file-attributes file)))) | ||
| 3996 | files)) | ||
| 3997 | ;; If there was a problem, use the values we could get but | ||
| 3998 | ;; don't let the cache prevent future reads. | ||
| 3999 | 0))) | ||
| 4000 | class-name)) | 3997 | class-name)) |
| 4001 | 3998 | ||
| 4002 | (define-obsolete-function-alias 'dir-locals-read-from-file | 3999 | (define-obsolete-function-alias 'dir-locals-read-from-file |
diff --git a/lisp/image-dired.el b/lisp/image-dired.el index 30ecc2befc7..175d9df5e8c 100644 --- a/lisp/image-dired.el +++ b/lisp/image-dired.el | |||
| @@ -582,10 +582,11 @@ Create the thumbnails directory if it does not exist." | |||
| 582 | "Return the image descriptor for a thumbnail of image file FILE." | 582 | "Return the image descriptor for a thumbnail of image file FILE." |
| 583 | (unless (string-match (image-file-name-regexp) file) | 583 | (unless (string-match (image-file-name-regexp) file) |
| 584 | (error "%s is not a valid image file" file)) | 584 | (error "%s is not a valid image file" file)) |
| 585 | (let ((thumb-file (image-dired-thumb-name file))) | 585 | (let* ((thumb-file (image-dired-thumb-name file)) |
| 586 | (unless (and (file-exists-p thumb-file) | 586 | (thumb-attr (file-attributes thumb-file))) |
| 587 | (<= (float-time (nth 5 (file-attributes file))) | 587 | (when (or (not thumb-attr) |
| 588 | (float-time (nth 5 (file-attributes thumb-file))))) | 588 | (time-less-p (nth 5 thumb-attr) |
| 589 | (nth 5 (file-attributes file)))) | ||
| 589 | (image-dired-create-thumb file thumb-file)) | 590 | (image-dired-create-thumb file thumb-file)) |
| 590 | (create-image thumb-file) | 591 | (create-image thumb-file) |
| 591 | ;; (list 'image :type 'jpeg | 592 | ;; (list 'image :type 'jpeg |
| @@ -748,10 +749,8 @@ Increase at own risk.") | |||
| 748 | 'image-dired-cmd-create-thumbnail-program) | 749 | 'image-dired-cmd-create-thumbnail-program) |
| 749 | (let* ((width (int-to-string (image-dired-thumb-size 'width))) | 750 | (let* ((width (int-to-string (image-dired-thumb-size 'width))) |
| 750 | (height (int-to-string (image-dired-thumb-size 'height))) | 751 | (height (int-to-string (image-dired-thumb-size 'height))) |
| 751 | (modif-time | 752 | (modif-time (format-time-string |
| 752 | (format "%.0f" | 753 | "%s" (nth 5 (file-attributes original-file)))) |
| 753 | (ffloor (float-time | ||
| 754 | (nth 5 (file-attributes original-file)))))) | ||
| 755 | (thumbnail-nq8-file (replace-regexp-in-string ".png\\'" "-nq8.png" | 754 | (thumbnail-nq8-file (replace-regexp-in-string ".png\\'" "-nq8.png" |
| 756 | thumbnail-file)) | 755 | thumbnail-file)) |
| 757 | (spec | 756 | (spec |
diff --git a/lisp/info.el b/lisp/info.el index 6f87adb04e8..e2f9953f7c7 100644 --- a/lisp/info.el +++ b/lisp/info.el | |||
| @@ -649,7 +649,7 @@ Do the right thing if the file has been compressed or zipped." | |||
| 649 | (attribs-new (and (stringp fullname) (file-attributes fullname))) | 649 | (attribs-new (and (stringp fullname) (file-attributes fullname))) |
| 650 | (modtime-new (and attribs-new (nth 5 attribs-new)))) | 650 | (modtime-new (and attribs-new (nth 5 attribs-new)))) |
| 651 | (when (and modtime-old modtime-new | 651 | (when (and modtime-old modtime-new |
| 652 | (> (float-time modtime-new) (float-time modtime-old))) | 652 | (time-less-p modtime-old modtime-new)) |
| 653 | (setq Info-index-nodes (remove (assoc (or Info-current-file filename) | 653 | (setq Info-index-nodes (remove (assoc (or Info-current-file filename) |
| 654 | Info-index-nodes) | 654 | Info-index-nodes) |
| 655 | Info-index-nodes)) | 655 | Info-index-nodes)) |
diff --git a/lisp/ls-lisp.el b/lisp/ls-lisp.el index 280e7f4bc3e..66dddbbc17b 100644 --- a/lisp/ls-lisp.el +++ b/lisp/ls-lisp.el | |||
| @@ -861,7 +861,7 @@ Use the same method as ls to decide whether to show time-of-day or year, | |||
| 861 | depending on distance between file date and the current time. | 861 | depending on distance between file date and the current time. |
| 862 | All ls time options, namely c, t and u, are handled." | 862 | All ls time options, namely c, t and u, are handled." |
| 863 | (let* ((time (nth (or time-index 5) file-attr)) ; default is last modtime | 863 | (let* ((time (nth (or time-index 5) file-attr)) ; default is last modtime |
| 864 | (diff (- (float-time time) (float-time))) | 864 | (diff (time-subtract time nil)) |
| 865 | ;; Consider a time to be recent if it is within the past six | 865 | ;; Consider a time to be recent if it is within the past six |
| 866 | ;; months. A Gregorian year has 365.2425 * 24 * 60 * 60 == | 866 | ;; months. A Gregorian year has 365.2425 * 24 * 60 * 60 == |
| 867 | ;; 31556952 seconds on the average, and half of that is 15778476. | 867 | ;; 31556952 seconds on the average, and half of that is 15778476. |
| @@ -878,7 +878,8 @@ All ls time options, namely c, t and u, are handled." | |||
| 878 | (if (member locale '("C" "POSIX")) | 878 | (if (member locale '("C" "POSIX")) |
| 879 | (setq locale nil)) | 879 | (setq locale nil)) |
| 880 | (format-time-string | 880 | (format-time-string |
| 881 | (if (and (<= past-cutoff diff) (<= diff 0)) | 881 | (if (and (not (time-less-p diff past-cutoff)) |
| 882 | (not (time-less-p 0 diff))) | ||
| 882 | (if (and locale (not ls-lisp-use-localized-time-format)) | 883 | (if (and locale (not ls-lisp-use-localized-time-format)) |
| 883 | "%m-%d %H:%M" | 884 | "%m-%d %H:%M" |
| 884 | (nth 0 ls-lisp-format-time-list)) | 885 | (nth 0 ls-lisp-format-time-list)) |
diff --git a/lisp/net/ange-ftp.el b/lisp/net/ange-ftp.el index 73f62c85519..cf65e10e510 100644 --- a/lisp/net/ange-ftp.el +++ b/lisp/net/ange-ftp.el | |||
| @@ -3479,7 +3479,7 @@ system TYPE.") | |||
| 3479 | (f2-mt (nth 5 (file-attributes f2)))) | 3479 | (f2-mt (nth 5 (file-attributes f2)))) |
| 3480 | (cond ((null f1-mt) nil) | 3480 | (cond ((null f1-mt) nil) |
| 3481 | ((null f2-mt) t) | 3481 | ((null f2-mt) t) |
| 3482 | (t (> (float-time f1-mt) (float-time f2-mt))))) | 3482 | (t (time-less-p f2-mt f1-mt)))) |
| 3483 | (ange-ftp-real-file-newer-than-file-p f1 f2)))) | 3483 | (ange-ftp-real-file-newer-than-file-p f1 f2)))) |
| 3484 | 3484 | ||
| 3485 | (defun ange-ftp-file-writable-p (file) | 3485 | (defun ange-ftp-file-writable-p (file) |
| @@ -3561,7 +3561,7 @@ Value is (0 0) if the modification time cannot be determined." | |||
| 3561 | (let ((file-mdtm (ange-ftp-file-modtime name)) | 3561 | (let ((file-mdtm (ange-ftp-file-modtime name)) |
| 3562 | (buf-mdtm (with-current-buffer buf (visited-file-modtime)))) | 3562 | (buf-mdtm (with-current-buffer buf (visited-file-modtime)))) |
| 3563 | (or (zerop (car file-mdtm)) | 3563 | (or (zerop (car file-mdtm)) |
| 3564 | (<= (float-time file-mdtm) (float-time buf-mdtm)))) | 3564 | (not (time-less-p buf-mdtm file-mdtm)))) |
| 3565 | (ange-ftp-real-verify-visited-file-modtime buf)))) | 3565 | (ange-ftp-real-verify-visited-file-modtime buf)))) |
| 3566 | 3566 | ||
| 3567 | (defun ange-ftp-file-size (file &optional ascii-mode) | 3567 | (defun ange-ftp-file-size (file &optional ascii-mode) |
diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el index 5c785daa8a2..3b6b6c8c807 100644 --- a/lisp/net/rcirc.el +++ b/lisp/net/rcirc.el | |||
| @@ -2333,7 +2333,7 @@ With a prefix arg, prompt for new topic." | |||
| 2333 | 2333 | ||
| 2334 | (defun rcirc-ctcp-sender-PING (process target _request) | 2334 | (defun rcirc-ctcp-sender-PING (process target _request) |
| 2335 | "Send a CTCP PING message to TARGET." | 2335 | "Send a CTCP PING message to TARGET." |
| 2336 | (let ((timestamp (format "%.0f" (float-time)))) | 2336 | (let ((timestamp (format-time-string "%s"))) |
| 2337 | (rcirc-send-ctcp process target "PING" timestamp))) | 2337 | (rcirc-send-ctcp process target "PING" timestamp))) |
| 2338 | 2338 | ||
| 2339 | (defun rcirc-cmd-me (args &optional process target) | 2339 | (defun rcirc-cmd-me (args &optional process target) |
diff --git a/lisp/textmodes/remember.el b/lisp/textmodes/remember.el index b20ee8fee84..730eaecc71c 100644 --- a/lisp/textmodes/remember.el +++ b/lisp/textmodes/remember.el | |||
| @@ -349,7 +349,7 @@ In which case `remember-mailbox' should be the name of the mailbox. | |||
| 349 | Each piece of pseudo-mail created will have an `X-Todo-Priority' | 349 | Each piece of pseudo-mail created will have an `X-Todo-Priority' |
| 350 | field, for the purpose of appropriate splitting." | 350 | field, for the purpose of appropriate splitting." |
| 351 | (let ((who (read-string "Who is this item related to? ")) | 351 | (let ((who (read-string "Who is this item related to? ")) |
| 352 | (moment (format "%.0f" (float-time))) | 352 | (moment (format-time-string "%s")) |
| 353 | (desc (remember-buffer-desc)) | 353 | (desc (remember-buffer-desc)) |
| 354 | (text (buffer-string))) | 354 | (text (buffer-string))) |
| 355 | (with-temp-buffer | 355 | (with-temp-buffer |
diff --git a/lisp/url/url-cookie.el b/lisp/url/url-cookie.el index 453d4fe5b6f..28dfcedeaca 100644 --- a/lisp/url/url-cookie.el +++ b/lisp/url/url-cookie.el | |||
| @@ -161,7 +161,7 @@ telling Microsoft that." | |||
| 161 | (let ((exp (url-cookie-expires cookie))) | 161 | (let ((exp (url-cookie-expires cookie))) |
| 162 | (and (> (length exp) 0) | 162 | (and (> (length exp) 0) |
| 163 | (condition-case () | 163 | (condition-case () |
| 164 | (> (float-time) (float-time (date-to-time exp))) | 164 | (time-less-p nil (date-to-time exp)) |
| 165 | (error nil))))) | 165 | (error nil))))) |
| 166 | 166 | ||
| 167 | (defun url-cookie-retrieve (host &optional localpart secure) | 167 | (defun url-cookie-retrieve (host &optional localpart secure) |