aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrea Monaco2022-12-09 21:22:22 +0100
committerEli Zaretskii2022-12-18 12:22:27 +0200
commit7cc2313eb0a765e4cfa8469b8db8dce4b207ae44 (patch)
treeb957ac821b1b4712ff279008c82c36e96f837534
parent88e59b16cbe293f480e7d142dd3c8cb01e7ff225 (diff)
downloademacs-7cc2313eb0a765e4cfa8469b8db8dce4b207ae44.tar.gz
emacs-7cc2313eb0a765e4cfa8469b8db8dce4b207ae44.zip
Make 'rmail-summary-by-thread' faster
* lisp/mail/rmailsum.el (rmail-summary-message-parents-vector) (rmail-summary-message-descendants-vector): Doc fixes. (rmail-summary-message-descendants-vector): New variable. (rmail-summary-fill-message-parents-and-descs-vectors): Renamed from 'rmail-summary-fill-message-parents-vector' and rewritten. (rmail-summary-direct-descendants): Function deleted.
-rw-r--r--lisp/mail/rmailsum.el62
1 files changed, 34 insertions, 28 deletions
diff --git a/lisp/mail/rmailsum.el b/lisp/mail/rmailsum.el
index b30c32aaffd..d63e05f5fa2 100644
--- a/lisp/mail/rmailsum.el
+++ b/lisp/mail/rmailsum.el
@@ -80,9 +80,14 @@ commands consecutively. Filled by
80 80
81(defvar rmail-summary-message-parents-vector nil 81(defvar rmail-summary-message-parents-vector nil
82 "Vector that holds a list of indices of parents for each message. 82 "Vector that holds a list of indices of parents for each message.
83Message A is parent to message B if the id of A appear in the 83Message A is parent of message B if the id of A appears in the
84References or In-reply-to fields of B, or if A is the first 84\"References\" or \"In-reply-to\" fields of B, or if A is the first
85message with the same subject as B. First element is ignored.") 85message with the same \"Subject\" as B. First element is ignored.")
86
87(defvar rmail-summary-message-descendants-vector nil
88 "Vector that holds the direct descendants of each message.
89This is the antipode of `rmail-summary-message-parents-vector'.
90First element is ignored.")
86 91
87(defvar rmail-summary-font-lock-keywords 92(defvar rmail-summary-font-lock-keywords
88 '(("^ *[0-9]+D.*" . font-lock-string-face) ; Deleted. 93 '(("^ *[0-9]+D.*" . font-lock-string-face) ; Deleted.
@@ -318,11 +323,13 @@ message with the same subject as B. First element is ignored.")
318(defun rmail-summary-fill-message-ids-hash-table () 323(defun rmail-summary-fill-message-ids-hash-table ()
319 "Fill `rmail-summary-message-ids-hash-table'." 324 "Fill `rmail-summary-message-ids-hash-table'."
320 (with-current-buffer rmail-buffer 325 (with-current-buffer rmail-buffer
321 (setq rmail-summary-message-ids-hash-table (make-hash-table :test 'equal :size 1024)) 326 (setq rmail-summary-message-ids-hash-table
327 (make-hash-table :test 'equal :size 1024))
322 (let ((msgnum 1)) 328 (let ((msgnum 1))
323 (while (<= msgnum rmail-total-messages) 329 (while (<= msgnum rmail-total-messages)
324 (let ((id (rmail-get-header "Message-ID" msgnum))) 330 (let ((id (rmail-get-header "Message-ID" msgnum)))
325 (puthash id (cons (cons id msgnum) (gethash id rmail-summary-message-ids-hash-table)) 331 (puthash id (cons (cons id msgnum)
332 (gethash id rmail-summary-message-ids-hash-table))
326 rmail-summary-message-ids-hash-table)) 333 rmail-summary-message-ids-hash-table))
327 (setq msgnum (1+ msgnum)))))) 334 (setq msgnum (1+ msgnum))))))
328 335
@@ -331,14 +338,18 @@ message with the same subject as B. First element is ignored.")
331 (if header 338 (if header
332 (split-string header "[ \f\t\n\r\v,;]+")))) 339 (split-string header "[ \f\t\n\r\v,;]+"))))
333 340
334(defun rmail-summary-fill-message-parents-vector () 341(defun rmail-summary-fill-message-parents-and-descs-vectors ()
335 "Fill `rmail-summary-message-parents-vector'." 342 "Fill parents and descendats vectors for messages.
343This populates `rmail-summary-message-parents-vector'
344and `rmail-summary-message-descendants-vector'."
336 (with-current-buffer rmail-buffer 345 (with-current-buffer rmail-buffer
337 (rmail-summary-fill-message-ids-hash-table) 346 (rmail-summary-fill-message-ids-hash-table)
338 (setq rmail-summary-subjects-hash-table 347 (setq rmail-summary-subjects-hash-table
339 (make-hash-table :test 'equal :size 1024)) 348 (make-hash-table :test 'equal :size 1024))
340 (setq rmail-summary-message-parents-vector 349 (setq rmail-summary-message-parents-vector
341 (make-vector (1+ rmail-total-messages) nil)) 350 (make-vector (1+ rmail-total-messages) nil))
351 (setq rmail-summary-message-descendants-vector
352 (make-vector (1+ rmail-total-messages) nil))
342 (let ((msgnum 1)) 353 (let ((msgnum 1))
343 (while (<= msgnum rmail-total-messages) 354 (while (<= msgnum rmail-total-messages)
344 (let* ((parents nil) 355 (let* ((parents nil)
@@ -346,18 +357,27 @@ message with the same subject as B. First element is ignored.")
346 (subj-cell (gethash subject rmail-summary-subjects-hash-table)) 357 (subj-cell (gethash subject rmail-summary-subjects-hash-table))
347 (subj-par (assoc subject subj-cell)) 358 (subj-par (assoc subject subj-cell))
348 (refs (rmail-summary--split-header-field "References" msgnum)) 359 (refs (rmail-summary--split-header-field "References" msgnum))
349 (reply-to (rmail-summary--split-header-field "In-reply-to" 360 (reply-tos (rmail-summary--split-header-field "In-reply-to"
350 msgnum))) 361 msgnum)))
351 (if subj-par 362 (if subj-par
352 (setq parents (cons (cdr subj-par) parents)) 363 (progn
364 (setq parents (cons (cdr subj-par) nil))
365 (aset rmail-summary-message-descendants-vector (cdr subj-par)
366 (cons msgnum
367 (aref rmail-summary-message-descendants-vector
368 (cdr subj-par)))))
353 (puthash subject (cons (cons subject msgnum) subj-cell) 369 (puthash subject (cons (cons subject msgnum) subj-cell)
354 rmail-summary-subjects-hash-table)) 370 rmail-summary-subjects-hash-table))
355 (dolist (id (append refs reply-to)) 371 (dolist (id (append refs reply-tos))
356 (let ((ent 372 (let ((ent
357 (assoc id 373 (assoc id
358 (gethash id rmail-summary-message-ids-hash-table)))) 374 (gethash id rmail-summary-message-ids-hash-table))))
359 (if ent 375 (when ent
360 (setq parents (cons (cdr ent) parents))))) 376 (setq parents (cons (cdr ent) parents))
377 (aset rmail-summary-message-descendants-vector (cdr ent)
378 (cons msgnum
379 (aref rmail-summary-message-descendants-vector
380 (cdr ent)))))))
361 (aset rmail-summary-message-parents-vector msgnum parents) 381 (aset rmail-summary-message-parents-vector msgnum parents)
362 (setq msgnum (1+ msgnum))))))) 382 (setq msgnum (1+ msgnum)))))))
363 383
@@ -387,20 +407,6 @@ the messages that are displayed."
387 (interactive) 407 (interactive)
388 (rmail-new-summary "All" '(rmail-summary) nil)) 408 (rmail-new-summary "All" '(rmail-summary) nil))
389 409
390(defun rmail-summary-direct-descendants (msgnum encountered-msgs)
391 "Find all direct descendants of MSGNUM, ignoring ENCOUNTERED-MSGS.
392Assumes `rmail-summary-message-parents-vector' is filled. Ignores messages
393already ticked in ENCOUNTERED-MSGS."
394 (let (desc
395 (msg 1))
396 (while (<= msg rmail-total-messages)
397 (when (and
398 (not (aref encountered-msgs msg))
399 (memq msgnum (aref rmail-summary-message-parents-vector msg)))
400 (setq desc (cons msg desc)))
401 (setq msg (1+ msg)))
402 desc))
403
404(defun rmail-summary--walk-thread-message-recursively (msgnum encountered-msgs) 410(defun rmail-summary--walk-thread-message-recursively (msgnum encountered-msgs)
405 "Add parents and descendants of message MSGNUM to ENCOUNTERED-MSGS, recursively." 411 "Add parents and descendants of message MSGNUM to ENCOUNTERED-MSGS, recursively."
406 (unless (aref encountered-msgs msgnum) 412 (unless (aref encountered-msgs msgnum)
@@ -412,7 +418,7 @@ already ticked in ENCOUNTERED-MSGS."
412 (mapc walk-thread-msg 418 (mapc walk-thread-msg
413 (aref rmail-summary-message-parents-vector msgnum)) 419 (aref rmail-summary-message-parents-vector msgnum))
414 (mapc walk-thread-msg 420 (mapc walk-thread-msg
415 (rmail-summary-direct-descendants msgnum encountered-msgs))))) 421 (aref rmail-summary-message-descendants-vector msgnum)))))
416 422
417;;;###autoload 423;;;###autoload
418(defun rmail-summary-by-thread (&optional msgnum) 424(defun rmail-summary-by-thread (&optional msgnum)
@@ -430,7 +436,7 @@ headers of the messages."
430 (unless (and rmail-summary-message-parents-vector 436 (unless (and rmail-summary-message-parents-vector
431 (= (length rmail-summary-message-parents-vector) 437 (= (length rmail-summary-message-parents-vector)
432 (1+ rmail-total-messages))) 438 (1+ rmail-total-messages)))
433 (rmail-summary-fill-message-parents-vector)) 439 (rmail-summary-fill-message-parents-and-descs-vectors))
434 (let ((enc-msgs (make-bool-vector (1+ rmail-total-messages) nil))) 440 (let ((enc-msgs (make-bool-vector (1+ rmail-total-messages) nil)))
435 (rmail-summary--walk-thread-message-recursively msgnum enc-msgs) 441 (rmail-summary--walk-thread-message-recursively msgnum enc-msgs)
436 (rmail-new-summary (format "thread containing message %d" msgnum) 442 (rmail-new-summary (format "thread containing message %d" msgnum)