[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master f4d7ca7 05/13: Simplify message-unique-id etc.
From: |
Paul Eggert |
Subject: |
master f4d7ca7 05/13: Simplify message-unique-id etc. |
Date: |
Mon, 6 Dec 2021 02:24:22 -0500 (EST) |
branch: master
commit f4d7ca73e3ab975fd920a2b0f2d1a7fdb5276d99
Author: Paul Eggert <eggert@cs.ucla.edu>
Commit: Paul Eggert <eggert@cs.ucla.edu>
Simplify message-unique-id etc.
* lisp/gnus/message.el (message-unique-id):
* lisp/net/sasl.el (sasl-unique-id-function):
Avoid unnecessary consing and reliance on internal timestamp
format by using (time-convert nil 'integer) which typically does
no consing, instead of using (current-time) and then ignoring
the subsecond parts of the generated list.
---
lisp/gnus/message.el | 24 +++++++++++++-----------
lisp/net/sasl.el | 23 +++++++++++++----------
2 files changed, 26 insertions(+), 21 deletions(-)
diff --git a/lisp/gnus/message.el b/lisp/gnus/message.el
index 562bc64..8e7983a 100644
--- a/lisp/gnus/message.el
+++ b/lisp/gnus/message.el
@@ -5828,15 +5828,15 @@ In posting styles use `(\"Expires\" (make-expires-date
30))'."
;; You might for example insert a "." somewhere (not next to another dot
;; or string boundary), or modify the "fsf" string.
(defun message-unique-id ()
- ;; Don't use microseconds from (current-time), they may be unsupported.
+ ;; Don't use fractional seconds from timestamp; they may be unsupported.
;; Instead we use this randomly inited counter.
(setq message-unique-id-char
- (% (1+ (or message-unique-id-char
- (random (ash 1 20))))
- ;; (current-time) returns 16-bit ints,
- ;; and 2^16*25 just fits into 4 digits i base 36.
- (* 25 25)))
- (let ((tm (current-time)))
+ ;; 2^16 * 25 just fits into 4 digits i base 36.
+ (let ((base (* 25 25)))
+ (if message-unique-id-char
+ (% (1+ message-unique-id-char) base)
+ (random base))))
+ (let ((tm (time-convert nil 'integer)))
(concat
(if (or (eq system-type 'ms-dos)
;; message-number-base36 doesn't handle bigints.
@@ -5846,10 +5846,12 @@ In posting styles use `(\"Expires\" (make-expires-date
30))'."
(aset user (match-beginning 0) ?_))
user)
(message-number-base36 (user-uid) -1))
- (message-number-base36 (+ (car tm)
- (ash (% message-unique-id-char 25) 16)) 4)
- (message-number-base36 (+ (nth 1 tm)
- (ash (/ message-unique-id-char 25) 16)) 4)
+ (message-number-base36 (+ (ash tm -16)
+ (ash (% message-unique-id-char 25) 16))
+ 4)
+ (message-number-base36 (+ (logand tm #xffff)
+ (ash (/ message-unique-id-char 25) 16))
+ 4)
;; Append a given name, because while the generated ID is unique
;; to this newsreader, other newsreaders might otherwise generate
;; the same ID via another algorithm.
diff --git a/lisp/net/sasl.el b/lisp/net/sasl.el
index b7f814f..0a3ecf9 100644
--- a/lisp/net/sasl.el
+++ b/lisp/net/sasl.el
@@ -174,21 +174,24 @@ It contain at least 64 bits of entropy."
;; stolen (and renamed) from message.el
(defun sasl-unique-id-function ()
- ;; Don't use microseconds from (current-time), they may be unsupported.
+ ;; Don't use fractional seconds from timestamp; they may be unsupported.
;; Instead we use this randomly inited counter.
(setq sasl-unique-id-char
- (% (1+ (or sasl-unique-id-char (logand (random) (1- (ash 1 20)))))
- ;; (current-time) returns 16-bit ints,
- ;; and 2^16*25 just fits into 4 digits i base 36.
- (* 25 25)))
- (let ((tm (current-time)))
+ ;; 2^16 * 25 just fits into 4 digits i base 36.
+ (let ((base (* 25 25)))
+ (if sasl-unique-id-char
+ (% (1+ sasl-unique-id-char) base)
+ (random base))))
+ (let ((tm (time-convert nil 'integer)))
(concat
(sasl-unique-id-number-base36
- (+ (car tm)
- (ash (% sasl-unique-id-char 25) 16)) 4)
+ (+ (ash tm -16)
+ (ash (% sasl-unique-id-char 25) 16))
+ 4)
(sasl-unique-id-number-base36
- (+ (nth 1 tm)
- (ash (/ sasl-unique-id-char 25) 16)) 4))))
+ (+ (logand tm #xffff)
+ (ash (/ sasl-unique-id-char 25) 16))
+ 4))))
(defun sasl-unique-id-number-base36 (num len)
(if (if (< len 0)
- master updated (4434dea -> c1145c3), Paul Eggert, 2021/12/06
- master c1145c3 13/13: Update org-compat doc string, Paul Eggert, 2021/12/06
- master 084f440 06/13: Simplify message-make-expires, Paul Eggert, 2021/12/06
- master dbef214 10/13: Simplify by using format-time-string, Paul Eggert, 2021/12/06
- master 83fa35b 02/13: Use time-equal-p to compare timestamps in tests, Paul Eggert, 2021/12/06
- master 524c42f 04/13: Prefer nil to (current-time) when either will do, Paul Eggert, 2021/12/06
- master 19932c3 11/13: Avoid timestamp info loss in mh-alias-tstamp, Paul Eggert, 2021/12/06
- master 2bda029 07/13: Use time-convert in with-decoded-time-value, Paul Eggert, 2021/12/06
- master 15f20c0 09/13: Simplify RFC 5322 time zone generation, Paul Eggert, 2021/12/06
- master f4d7ca7 05/13: Simplify message-unique-id etc.,
Paul Eggert <=
- master 1866373 08/13: Fix image load timekeeping bug, Paul Eggert, 2021/12/06
- master af60618 03/13: Simplify cedet-utest-elapsed-time, Paul Eggert, 2021/12/06
- master 0d88c3c 01/13: Add time-convert tests, Paul Eggert, 2021/12/06
- master a21b8c5 12/13: Fix minor clock skew issues, Paul Eggert, 2021/12/06