emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r104831: Merge: Time-stamp simplifica


From: Paul Eggert
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r104831: Merge: Time-stamp simplifications and fixes.
Date: Thu, 30 Jun 2011 22:21:19 -0700
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 104831 [merge]
committer: Paul Eggert <address@hidden>
branch nick: trunk
timestamp: Thu 2011-06-30 22:21:19 -0700
message:
  Merge: Time-stamp simplifications and fixes.
modified:
  lisp/ChangeLog
  lisp/allout-widgets.el
  lisp/calendar/timeclock.el
  lisp/cedet/ChangeLog
  lisp/cedet/semantic.el
  lisp/emacs-lisp/benchmark.el
  lisp/emacs-lisp/elp.el
  lisp/emacs-lisp/timer.el
  lisp/erc/erc.el
  lisp/gnus/ChangeLog
  lisp/gnus/gnus-util.el
  lisp/gnus/nntp.el
  lisp/nxml/rng-maint.el
  lisp/play/hanoi.el
  lisp/type-break.el
  lisp/vc/ediff-util.el
  lisp/woman.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2011-07-01 03:48:44 +0000
+++ b/lisp/ChangeLog    2011-07-01 05:20:09 +0000
@@ -1,3 +1,34 @@
+2011-07-01  Paul Eggert  <address@hidden>
+
+       Time-stamp simplifications and fixes.
+       These improve accuracy slightly, and future-proof the code
+       against some potential changes to current-time format.
+
+       * woman.el (woman-decode-buffer, WoMan-log-end): Log fractional secs
+       by using time-since and float-time.
+
+       * vc/ediff-util.el (ediff-calc-command-time): Use time-since
+       and float-time.  Say "NNN.NNN seconds" rather than "NNN seconds
+       + NNN microseconds".
+
+       * type-break.el (type-break-time-sum): Rewrite using time-add.
+
+       * play/hanoi.el (hanoi-current-time-float): Remove.
+       All uses replaced by float-time.
+
+       * nxml/rng-maint.el (rng-time-function): Rewrite using time-subtract.
+       This yields a more-accurate answer.
+       (rng-time-to-float): Remove; no longer needed.
+
+       * emacs-lisp/timer.el (timer-relative-time): Use time-add.
+
+       * calendar/timeclock.el (timeclock-seconds-to-time):
+       Defalias to seconds-to-time, since they're the same thing.
+
+       * emacs-lisp/elp.el (elp-elapsed-time):
+       * emacs-lisp/benchmark.el (benchmark-elapse):
+       * allout-widgets.el (allout-elapsed-time-seconds): Use float-time.
+
 2011-07-01  Stefan Monnier  <address@hidden>
 
        * window.el (bury-buffer): Don't iconify the only frame.

=== modified file 'lisp/allout-widgets.el'
--- a/lisp/allout-widgets.el    2011-06-26 16:47:39 +0000
+++ b/lisp/allout-widgets.el    2011-07-01 00:11:50 +0000
@@ -2324,9 +2324,7 @@
 (defun allout-elapsed-time-seconds (end start)
   "Return seconds between `current-time' style time START/END triples."
   (let ((elapsed (time-subtract end start)))
-    (+ (* (car elapsed) (expt 2.0 16))
-       (cadr elapsed)
-       (/ (caddr elapsed) (expt 10.0 6)))))
+    (float-time elapsed)))
 ;;;_  > allout-frame-property (frame property)
 (defalias 'allout-frame-property
   (cond ((fboundp 'frame-parameter)

=== modified file 'lisp/calendar/timeclock.el'
--- a/lisp/calendar/timeclock.el        2011-05-07 01:24:04 +0000
+++ b/lisp/calendar/timeclock.el        2011-07-01 00:20:59 +0000
@@ -545,11 +545,7 @@
 (defalias 'timeclock-time-to-seconds (if (fboundp 'float-time) 'float-time
                                       'time-to-seconds))
 
-(defsubst timeclock-seconds-to-time (seconds)
-  "Convert SECONDS (a floating point number) to an Emacs time structure."
-  (list (floor seconds 65536)
-       (floor (mod seconds 65536))
-       (floor (* (- seconds (ffloor seconds)) 1000000))))
+(defalias 'timeclock-seconds-to-time 'seconds-to-time)
 
 ;; Should today-only be removed in favour of timeclock-relative? - gm
 (defsubst timeclock-when-to-leave (&optional today-only)

=== modified file 'lisp/cedet/ChangeLog'
--- a/lisp/cedet/ChangeLog      2011-05-12 16:30:17 +0000
+++ b/lisp/cedet/ChangeLog      2011-07-01 00:24:48 +0000
@@ -1,3 +1,8 @@
+2011-07-01  Paul Eggert  <address@hidden>
+
+       * semantic.el (semantic-elapsed-time): Rewrite using
+       time-subtract and float-time.
+
 2011-05-11  Glenn Morris  <address@hidden>
 
        * semantic/wisent/javascript.el (semantic-get-local-variables):

=== modified file 'lisp/cedet/semantic.el'
--- a/lisp/cedet/semantic.el    2011-01-25 04:08:28 +0000
+++ b/lisp/cedet/semantic.el    2011-07-01 00:24:48 +0000
@@ -379,9 +379,7 @@
 (defun semantic-elapsed-time (start end)
   "Copied from elp.el.  Was `elp-elapsed-time'.
 Argument START and END bound the time being calculated."
-  (+ (* (- (car end) (car start)) 65536.0)
-     (- (car (cdr end)) (car (cdr start)))
-     (/ (- (car (cdr (cdr end))) (car (cdr (cdr start)))) 1000000.0)))
+  (float-time (time-subtract end start)))
 
 (defun bovinate (&optional clear)
   "Parse the current buffer.  Show output in a temp buffer.

=== modified file 'lisp/emacs-lisp/benchmark.el'
--- a/lisp/emacs-lisp/benchmark.el      2011-01-26 08:36:39 +0000
+++ b/lisp/emacs-lisp/benchmark.el      2011-07-01 00:27:45 +0000
@@ -39,9 +39,8 @@
        (setq ,t1 (current-time))
        ,@forms
        (setq ,t2 (current-time))
-       (+ (* (- (car ,t2) (car ,t1)) 65536.0)
-         (- (nth 1 ,t2) (nth 1 ,t1))
-         (* (- (nth 2 ,t2) (nth 2 ,t1)) 1.0e-6)))))
+       (float-time (time-subtract ,t2 ,t1)))))
+
 (put 'benchmark-elapse 'edebug-form-spec t)
 (put 'benchmark-elapse 'lisp-indent-function 0)
 

=== modified file 'lisp/emacs-lisp/elp.el'
--- a/lisp/emacs-lisp/elp.el    2011-03-06 02:38:48 +0000
+++ b/lisp/emacs-lisp/elp.el    2011-07-01 00:30:18 +0000
@@ -282,7 +282,7 @@
     ;; the function so that non-local exists are still recorded. TBD:
     ;; I haven't tested non-local exits at all, so no guarantees.
     ;;
-    ;; The 1st element is the total amount of time in usecs that have
+    ;; The 1st element is the total amount of time in seconds that has
     ;; been spent inside this function.  This number is added to on
     ;; function exit.
     ;;
@@ -424,9 +424,7 @@
 
 
 (defsubst elp-elapsed-time (start end)
-  (+ (* (- (car end) (car start)) 65536.0)
-     (- (car (cdr end)) (car (cdr start)))
-     (/ (- (car (cdr (cdr end))) (car (cdr (cdr start)))) 1000000.0)))
+  (float-time (time-subtract end start)))
 
 (defun elp-wrapper (funsym interactive-p args)
   "This function has been instrumented for profiling by the ELP.

=== modified file 'lisp/emacs-lisp/timer.el'
--- a/lisp/emacs-lisp/timer.el  2011-06-04 22:46:26 +0000
+++ b/lisp/emacs-lisp/timer.el  2011-07-01 01:27:40 +0000
@@ -110,27 +110,12 @@
 (defun timer-relative-time (time secs &optional usecs)
   "Advance TIME by SECS seconds and optionally USECS microseconds.
 SECS may be either an integer or a floating point number."
-  ;; FIXME: we should just use (time-add time (list 0 secs usecs))
-  (let ((high (car time))
-       (low (if (consp (cdr time)) (nth 1 time) (cdr time)))
-       (micro (if (numberp (car-safe (cdr-safe (cdr time))))
-                  (nth 2 time)
-                0)))
-    ;; Add
-    (if usecs (setq micro (+ micro usecs)))
-    (if (floatp secs)
-       (setq micro (+ micro (floor (* 1000000 (- secs (floor secs)))))))
-    (setq low (+ low (floor secs)))
-
-    ;; Normalize
-    ;; `/' rounds towards zero while `mod' returns a positive number,
-    ;; so we can't rely on (= a (+ (* 100 (/ a 100)) (mod a 100))).
-    (setq low (+ low (/ micro 1000000) (if (< micro 0) -1 0)))
-    (setq micro (mod micro 1000000))
-    (setq high (+ high (/ low 65536) (if (< low 0) -1 0)))
-    (setq low (logand low 65535))
-
-    (list high low (and (/= micro 0) micro))))
+  (let ((delta (if (floatp secs)
+                  (seconds-to-time secs)
+                (list (floor secs 65536) (mod secs 65536)))))
+    (if usecs
+       (setq delta (time-add delta (list 0 0 usecs))))
+    (time-add time delta)))
 
 (defun timer--time-less-p (t1 t2)
   "Say whether time value T1 is less than time value T2."

=== modified file 'lisp/erc/erc.el'
--- a/lisp/erc/erc.el   2011-06-23 00:18:46 +0000
+++ b/lisp/erc/erc.el   2011-07-01 01:29:04 +0000
@@ -2362,7 +2362,7 @@
        (cond ((integerp elt)           ; POSITION
               (incf (car list) shift))
              ((or (atom elt)           ; nil, EXTENT
-                  ;; (eq t (car elt))  ; (t HIGH . LOW)
+                  ;; (eq t (car elt))  ; (t . TIME)
                   (markerp (car elt))) ; (MARKER . DISTANCE)
               nil)
              ((integerp (car elt))     ; (BEGIN . END)
@@ -6493,4 +6493,3 @@
 ;; indent-tabs-mode: t
 ;; tab-width: 8
 ;; End:
-

=== modified file 'lisp/gnus/ChangeLog'
--- a/lisp/gnus/ChangeLog       2011-07-01 04:08:50 +0000
+++ b/lisp/gnus/ChangeLog       2011-07-01 05:20:09 +0000
@@ -1,3 +1,11 @@
+2011-07-01  Paul Eggert  <address@hidden>
+
+       * nntp.el (nntp-record-command):
+       * gnus-util.el (gnus-message-with-timestamp-1):
+       Use format-time-string rather than decoding time stamps by hand.
+       This is simpler and insulates the code from potential changes to
+       current-time format.
+
 2011-07-01  Katsumi Yamaoka  <address@hidden>
 
        * gnus-draft.el (gnus-draft-clear-marks): Mark deleted articles as read.

=== modified file 'lisp/gnus/gnus-util.el'
--- a/lisp/gnus/gnus-util.el    2011-03-19 00:48:04 +0000
+++ b/lisp/gnus/gnus-util.el    2011-07-01 01:46:17 +0000
@@ -540,8 +540,7 @@
 
 (eval-when-compile
   (defmacro gnus-message-with-timestamp-1 (format-string args)
-    (let ((timestamp '((format-time-string "%Y%m%dT%H%M%S" time)
-                      "." (format "%03d" (/ (nth 2 time) 1000)) "> ")))
+    (let ((timestamp '(format-time-string "%Y%m%dT%H%M%S.%3N> " time)))
       (if (featurep 'xemacs)
          `(let (str time)
             (if (or (and (null ,format-string) (null ,args))
@@ -554,10 +553,10 @@
               (cond ((eq gnus-add-timestamp-to-message 'log)
                      (setq time (current-time))
                      (display-message 'no-log str)
-                     (log-message 'message (concat ,@timestamp str)))
+                     (log-message 'message (concat ,timestamp str)))
                     (gnus-add-timestamp-to-message
                      (setq time (current-time))
-                     (display-message 'message (concat ,@timestamp str)))
+                     (display-message 'message (concat ,timestamp str)))
                     (t
                      (display-message 'message str))))
             str)
@@ -571,7 +570,7 @@
                    (setq time (current-time))
                    (with-current-buffer (get-buffer-create "*Messages*")
                      (goto-char (point-max))
-                     (insert ,@timestamp str "\n")
+                     (insert ,timestamp str "\n")
                      (forward-line (- message-log-max))
                      (delete-region (point-min) (point))
                      (goto-char (point-max))))
@@ -585,7 +584,7 @@
                          (and ,format-string str)
                        (message nil))
                    (setq time (current-time))
-                   (message "%s" (concat ,@timestamp str))
+                   (message "%s" (concat ,timestamp str))
                    str))
                 (t
                  (apply 'message ,format-string ,args))))))))

=== modified file 'lisp/gnus/nntp.el'
--- a/lisp/gnus/nntp.el 2011-05-18 14:17:34 +0000
+++ b/lisp/gnus/nntp.el 2011-07-01 01:49:43 +0000
@@ -338,10 +338,8 @@
   "Record the command STRING."
   (with-current-buffer (get-buffer-create "*nntp-log*")
     (goto-char (point-max))
-    (let ((time (current-time)))
-      (insert (format-time-string "%Y%m%dT%H%M%S" time)
-             "." (format "%03d" (/ (nth 2 time) 1000))
-             " " nntp-address " " string "\n"))))
+    (insert (format-time-string "%Y%m%dT%H%M%S.%3N")
+           " " nntp-address " " string "\n")))
 
 (defun nntp-report (&rest args)
   "Report an error from the nntp backend.  The first string in ARGS

=== modified file 'lisp/nxml/rng-maint.el'
--- a/lisp/nxml/rng-maint.el    2011-01-25 04:08:28 +0000
+++ b/lisp/nxml/rng-maint.el    2011-07-01 01:52:41 +0000
@@ -224,19 +224,13 @@
 
 ;;; Timing
 
-(defun rng-time-to-float (time)
-  (+ (* (nth 0 time) 65536.0)
-     (nth 1 time)
-     (/ (nth 2 time) 1000000.0)))
-
 (defun rng-time-function (function &rest args)
   (let* ((start (current-time))
         (val (apply function args))
         (end (current-time)))
     (message "%s ran in %g seconds"
             function
-            (- (rng-time-to-float end)
-               (rng-time-to-float start)))
+            (float-time (time-subtract end start)))
     val))
 
 (defun rng-time-tokenize-buffer ()

=== modified file 'lisp/play/hanoi.el'
--- a/lisp/play/hanoi.el        2011-04-21 12:24:46 +0000
+++ b/lisp/play/hanoi.el        2011-07-01 01:55:02 +0000
@@ -113,7 +113,7 @@
             (prefix-numeric-value current-prefix-arg))))
   (if (< nrings 0)
       (error "Negative number of rings"))
-  (hanoi-internal nrings (make-list nrings 0) (hanoi-current-time-float)))
+  (hanoi-internal nrings (make-list nrings 0) (float-time)))
 
 ;;;###autoload
 (defun hanoi-unix ()
@@ -123,7 +123,7 @@
 
 Repent before ring 31 moves."
   (interactive)
-  (let* ((start (ftruncate (hanoi-current-time-float)))
+  (let* ((start (ftruncate (float-time)))
         (bits (loop repeat 32
                     for x = (/ start (expt 2.0 31)) then (* x 2.0)
                     collect (truncate (mod x 2.0))))
@@ -137,7 +137,7 @@
 current-time interface is made s2G-compliant, hanoi.el will need
 to be updated."
   (interactive)
-  (let* ((start (ftruncate (hanoi-current-time-float)))
+  (let* ((start (ftruncate (float-time)))
         (bits (loop repeat 64
                     for x = (/ start (expt 2.0 63)) then (* x 2.0)
                     collect (truncate (mod x 2.0))))
@@ -283,11 +283,6 @@
     (setq buffer-read-only t)
     (force-mode-line-update)))
 
-(defun hanoi-current-time-float ()
-  "Return values from current-time combined into a single float."
-  (destructuring-bind (high low micros) (current-time)
-    (+ (* high 65536.0) low (/ micros 1000000.0))))
-
 (defun hanoi-put-face (start end value &optional object)
   "If hanoi-use-faces is non-nil, call put-text-property for face property."
   (if hanoi-use-faces
@@ -383,7 +378,7 @@
                    (/ (- tick flyward-ticks fly-ticks)
                       ticks-per-pole-step))))))))
     (if hanoi-move-period
-       (loop for elapsed = (- (hanoi-current-time-float) start-time)
+       (loop for elapsed = (- (float-time) start-time)
              while (< elapsed hanoi-move-period)
              with tick-period = (/ (float hanoi-move-period) total-ticks)
              for tick = (ceiling (/ elapsed tick-period)) do

=== modified file 'lisp/type-break.el'
--- a/lisp/type-break.el        2011-05-14 20:14:25 +0000
+++ b/lisp/type-break.el        2011-07-01 04:36:40 +0000
@@ -1008,34 +1008,14 @@
 ;; the result is passed to `current-time-string' it will toss some of the
 ;; "low" bits and format the time incorrectly.
 (defun type-break-time-sum (&rest tmlist)
-  (let ((high 0)
-        (low 0)
-        (micro 0)
-        tem)
+  (let ((sum '(0 0 0)))
     (while tmlist
       (setq tem (car tmlist))
       (setq tmlist (cdr tmlist))
-      (cond
-       ((numberp tem)
-        (setq low (+ low tem)))
-       (t
-        (setq high  (+ high  (or (car tem) 0)))
-        (setq low   (+ low   (or (car (cdr tem)) 0)))
-        (setq micro (+ micro (or (car (cdr (cdr tem))) 0))))))
-
-    (and (>= micro 1000000)
-         (progn
-           (setq tem (/ micro 1000000))
-           (setq low (+ low tem))
-           (setq micro (- micro (* tem 1000000)))))
-
-    (setq tem (lsh low -16))
-    (and (> tem 0)
-         (progn
-           (setq low (logand low 65535))
-           (setq high (+ high tem))))
-
-    (list high low micro)))
+      (setq sum (time-add sum (if (integerp tem)
+                                 (list (floor tem 65536) (mod tem 65536))
+                               tem))))
+    sum))
 
 (defun type-break-time-stamp (&optional when)
   (if (fboundp 'format-time-string)

=== modified file 'lisp/vc/ediff-util.el'
--- a/lisp/vc/ediff-util.el     2011-05-23 17:57:17 +0000
+++ b/lisp/vc/ediff-util.el     2011-07-01 04:44:40 +0000
@@ -4144,15 +4144,9 @@
 
 ;; calculate time used by command
 (defun ediff-calc-command-time ()
-  (let ((end (current-time))
-       micro sec)
-    (setq micro
-         (if (>= (nth 2 end) (nth 2 ediff-command-begin-time))
-             (- (nth 2 end) (nth 2 ediff-command-begin-time))
-           (+ (nth 2 end) (- 1000000 (nth 2 ediff-command-begin-time)))))
-    (setq sec (- (nth 1 end) (nth 1 ediff-command-begin-time)))
-    (or (equal ediff-command-begin-time '(0 0 0))
-       (message "Elapsed time: %d second(s) + %d microsecond(s)" sec micro))))
+  (or (equal ediff-command-begin-time '(0 0 0))
+      (message "Elapsed time: %g second(s)"
+              (float-time (time-since ediff-command-begin-time)))))
 
 (defsubst ediff-save-time ()
   (setq ediff-command-begin-time (current-time)))

=== modified file 'lisp/woman.el'
--- a/lisp/woman.el     2011-04-19 13:44:55 +0000
+++ b/lisp/woman.el     2011-07-01 04:52:27 +0000
@@ -2157,8 +2157,8 @@
   (run-hooks 'woman-pre-format-hook)
   (and (boundp 'font-lock-mode) font-lock-mode (font-lock-mode -1))
   ;; (fundamental-mode)
-  (let ((start-time (current-time))    ; (HIGH LOW MICROSEC)
-       time)                           ; HIGH * 2**16 + LOW seconds
+  (let ((start-time (current-time))
+       time)
     (message "WoMan formatting buffer...")
 ;  (goto-char (point-min))
 ;  (cond
@@ -2167,10 +2167,8 @@
 ;    (delete-region (point-min) (point))) ; potentially dangerous!
 ;   (t (message "WARNING: .TH request not found -- not man-page format?")))
     (woman-decode-region (point-min) (point-max))
-    (setq time (current-time)
-         time (+ (* (- (car time) (car start-time)) 65536)
-                 (- (cadr time) (cadr start-time))))
-    (message "WoMan formatting buffer...done in %d seconds" time)
+    (setq time (float-time (time-since start-time)))
+    (message "WoMan formatting buffer...done in %g seconds" time)
     (WoMan-log-end time))
   (run-hooks 'woman-post-format-hook))
 
@@ -4529,7 +4527,7 @@
   "Log the end of formatting in *WoMan-Log*.
 TIME specifies the time it took to format the man page, to be printed
 with the message."
-  (WoMan-log-1 (format "Formatting time %d seconds." time) 'end))
+  (WoMan-log-1 (format "Formatting time %g seconds." time) 'end))
 
 (defun WoMan-log-1 (string &optional end)
   "Log a message STRING in *WoMan-Log*.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]