>From b360958263800408081fc5b7a92fb219c46a43a5 Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" Date: Mon, 25 Mar 2019 02:22:58 +0000 Subject: [PATCH] * lisp/gnus/gnus-dup.el: Use lexical-binding (gnus-dup-list-dirty): Add docstring. (gnus-dup-open): Allocate gnus-dup-hashtb more conservatively now that it is no longer an obarray. (gnus-dup-enter-articles): Fix off-by-one error and De Morgan. (gnus-dup-suppress-articles): DRY. --- lisp/gnus/gnus-dup.el | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/lisp/gnus/gnus-dup.el b/lisp/gnus/gnus-dup.el index 8b876489e1..e2de5d0c8e 100644 --- a/lisp/gnus/gnus-dup.el +++ b/lisp/gnus/gnus-dup.el @@ -1,4 +1,4 @@ -;;; gnus-dup.el --- suppression of duplicate articles in Gnus +;;; gnus-dup.el --- suppression of duplicate articles in Gnus -*- lexical-binding: t -*- ;; Copyright (C) 1996-2019 Free Software Foundation, Inc. @@ -57,10 +57,12 @@ gnus-duplicate-file (defvar gnus-dup-list nil "List of seen message IDs, as strings.") + (defvar gnus-dup-hashtb nil "Hash table of seen message IDs, for fast lookup.") -(defvar gnus-dup-list-dirty nil) +(defvar gnus-dup-list-dirty nil + "Non-nil if `gnus-dup-list' needs to be saved.") ;;; ;;; Starting and stopping @@ -80,7 +82,7 @@ gnus-dup-open (if gnus-save-duplicate-list (gnus-dup-read) (setq gnus-dup-list nil)) - (setq gnus-dup-hashtb (gnus-make-hashtable gnus-duplicate-list-length)) + (setq gnus-dup-hashtb (gnus-make-hashtable)) ;; Enter all Message-IDs into the hash table. (dolist (g gnus-dup-list) (puthash g t gnus-dup-hashtb))) @@ -112,20 +114,22 @@ gnus-dup-enter-articles ;; Enter the Message-IDs of all read articles into the list ;; and hash table. (dolist (datum gnus-newsgroup-data) - (when (and (not (gnus-data-pseudo-p datum)) - (> (gnus-data-number datum) 0) - (not (memq (gnus-data-number datum) gnus-newsgroup-unreads)) - (not (= (gnus-data-mark datum) gnus-canceled-mark)) - (setq msgid (mail-header-id (gnus-data-header datum))) - (not (nnheader-fake-message-id-p msgid)) - (not (gethash msgid gnus-dup-hashtb))) + (unless (or (gnus-data-pseudo-p datum) + (<= (gnus-data-number datum) 0) + (memq (gnus-data-number datum) gnus-newsgroup-unreads) + (= (gnus-data-mark datum) gnus-canceled-mark) + (not (setq msgid (mail-header-id (gnus-data-header datum)))) + (nnheader-fake-message-id-p msgid) + (gethash msgid gnus-dup-hashtb)) (push msgid gnus-dup-list) (puthash msgid t gnus-dup-hashtb)))) - ;; Chop off excess Message-IDs from the list. - (let ((end (nthcdr gnus-duplicate-list-length gnus-dup-list))) + ;; Remove excess Message-IDs from the list and hash table. + (let* ((dups (cons nil gnus-dup-list)) + (end (nthcdr gnus-duplicate-list-length dups))) (when end (mapc (lambda (id) (remhash id gnus-dup-hashtb)) (cdr end)) - (setcdr end nil)))) + (setcdr end nil)) + (setq gnus-dup-list (cdr dups)))) (defun gnus-dup-suppress-articles () "Mark duplicate articles as read." @@ -137,10 +141,9 @@ gnus-dup-suppress-articles number) (dolist (header gnus-newsgroup-headers) (when (and (gethash (mail-header-id header) gnus-dup-hashtb) - (gnus-summary-article-unread-p (mail-header-number header))) - (setq gnus-newsgroup-unreads - (delq (setq number (mail-header-number header)) - gnus-newsgroup-unreads)) + (setq number (mail-header-number header)) + (gnus-summary-article-unread-p number)) + (setq gnus-newsgroup-unreads (delq number gnus-newsgroup-unreads)) (if (not auto) (push (cons number gnus-duplicate-mark) gnus-newsgroup-reads) (push number gnus-newsgroup-expirable) -- 2.20.1