Subject: bug#33653: 27.0.50; Change Gnus obarrays-as-hash-tables into real hash tables

From: "Basil L. Contovounesios" <[email-masked]>
Date: Thu, 11 Apr 2019 22:29:23 +0100

>From 5d3eb57ae62decf6316ab7c882cc6f18a9c63ae3 Mon Sep 17 00:00:00 2001
From: "Basil L. Contovounesios" <[email-masked]>
Date: Thu, 11 Apr 2019 17:24:36 +0100
Subject: [PATCH] Always set gnus-group property to a group name

* lisp/gnus/gnus-group.el (gnus-group-prepare-flat-list-dead):
Set gnus-group property to a group name, not active info.
Simplify surrounding logic.
(gnus-group-prepare-flat, gnus-group-goto-group): Use accessor
macros.
(gnus-group-insert-group-line, gnus-group-new-mail)
(gnus-group-mark-group): Write ?\s instead of ? .
(gnus-group-group-name, gnus-group-list-active): Simplify.
---
 lisp/gnus/gnus-group.el | 98 ++++++++++++++++++-----------------------
 1 file changed, 43 insertions(+), 55 deletions(-)

diff --git a/lisp/gnus/gnus-group.el b/lisp/gnus/gnus-group.el
index e1554cab8a..b1e4091c97 100644
--- a/lisp/gnus/gnus-group.el
+++ b/lisp/gnus/gnus-group.el
@@ -1320,7 +1320,7 @@ gnus-group-prepare-flat
 	      gnus-group-listed-groups)
       ;; List living groups, according to order in `gnus-group-list'.
       (dolist (g (cdr gnus-group-list))
-	(setq info (nth 1 (gethash g gnus-newsrc-hashtb))
+        (setq info (gnus-get-info g)
 	      group (gnus-info-group info)
 	      params (gnus-info-params info)
 	      unread (gnus-group-unread group))
@@ -1389,39 +1389,35 @@ gnus-group-prepare-flat-list-dead
   ;; List zombies and killed lists somewhat faster, which was
   ;; suggested by Jack Vinson <[email-masked]>.  It does
   ;; this by ignoring the group format specification altogether.
-  (let (group)
-    (if (> (length groups) gnus-group-listing-limit)
-	(while groups
-	  (setq group (pop groups))
-	  (when (gnus-group-prepare-logic
-		 group
-		 (or (not regexp)
-		     (and (stringp regexp) (string-match regexp group))
-		     (and (functionp regexp) (funcall regexp group))))
-	    (add-text-properties
-	     (point) (prog1 (1+ (point))
-		       (insert " " mark "     *: "
-			       (gnus-group-decoded-name group)
-			       "\n"))
-	     (list 'gnus-group (gethash group gnus-active-hashtb)
-		   'gnus-unread t
-		   'gnus-level level))))
-      (while groups
-	(setq group (pop groups))
+  (if (nthcdr gnus-group-listing-limit groups)
+      (dolist (group groups)
 	(when (gnus-group-prepare-logic
 	       group
-	       (or (not regexp)
-		   (and (stringp regexp) (string-match regexp group))
-		   (and (functionp regexp) (funcall regexp group))))
-	  (gnus-group-insert-group-line
-	   group level nil
-	   (let ((active (gnus-active group)))
-	     (if active
-		 (if (zerop (cdr active))
-		     0
-		   (- (1+ (cdr active)) (car active)))
-	       nil))
-	   (gnus-method-simplify (gnus-find-method-for-group group))))))))
+               (cond ((not regexp))
+                     ((stringp regexp) (string-match-p regexp group))
+                     ((functionp regexp) (funcall regexp group))))
+          (add-text-properties
+           (point) (prog1 (1+ (point))
+                     (insert " " mark "     *: "
+                             (gnus-group-decoded-name group)
+                             "\n"))
+           (list 'gnus-group group
+                 'gnus-unread t
+                 'gnus-level level))))
+    (dolist (group groups)
+      (when (gnus-group-prepare-logic
+             group
+             (cond ((not regexp))
+                   ((stringp regexp) (string-match-p regexp group))
+                   ((functionp regexp) (funcall regexp group))))
+        (gnus-group-insert-group-line
+         group level nil
+         (let ((active (gnus-active group)))
+           (and active
+                (if (zerop (cdr active))
+                    0
+                  (- (cdr active) (car active) -1))))
+         (gnus-method-simplify (gnus-find-method-for-group group)))))))
 
 (defun gnus-group-update-group-line ()
   "Update the current line in the group buffer."
@@ -1527,7 +1523,7 @@ gnus-group-insert-group-line
 	      (int-to-string (max 0 (- gnus-tmp-number-total number)))
 	    "*"))
 	 (gnus-tmp-subscribed
-	  (cond ((<= gnus-tmp-level gnus-level-subscribed) ? )
+          (cond ((<= gnus-tmp-level gnus-level-subscribed) ?\s)
 		((<= gnus-tmp-level gnus-level-unsubscribed) ?U)
 		((= gnus-tmp-level gnus-level-zombie) ?Z)
 		(t ?K)))
@@ -1546,7 +1542,7 @@ gnus-group-insert-group-line
 	 (gnus-tmp-moderated
 	  (if (and gnus-moderated-hashtb
 		   (gethash gnus-tmp-group gnus-moderated-hashtb))
-	      ?m ? ))
+              ?m ?\s))
 	 (gnus-tmp-moderated-string
 	  (if (eq gnus-tmp-moderated ?m) "(m)" ""))
          (gnus-tmp-group-icon (gnus-group-get-icon gnus-tmp-group))
@@ -1560,15 +1556,15 @@ gnus-group-insert-group-line
 	  (if (and (numberp number)
 		   (zerop number)
 		   (cdr (assq 'tick gnus-tmp-marked)))
-	      ?* ? ))
+              ?* ?\s))
 	 (gnus-tmp-summary-live
 	  (if (and (not gnus-group-is-exiting-p)
 		   (gnus-buffer-live-p (gnus-summary-buffer-name
 					gnus-tmp-group)))
-	      ?* ? ))
+              ?* ?\s))
 	 (gnus-tmp-process-marked
 	  (if (member gnus-tmp-group gnus-group-marked)
-	      gnus-process-mark ? ))
+              gnus-process-mark ?\s))
 	 (buffer-read-only nil)
 	 beg end
          gnus-tmp-header)	  ; passed as parameter to user-funcs.
@@ -1768,10 +1764,8 @@ gnus-group-set-mode-line
 (defun gnus-group-group-name ()
   "Get the name of the newsgroup on the current line."
   (let ((group (get-text-property (point-at-bol) 'gnus-group)))
-    (when group
-      (if (stringp group)
-	  group
-	(symbol-name group)))))
+    (cond ((stringp group) group)
+          (group (symbol-name group)))))
 
 (defun gnus-group-group-level ()
   "Get the level of the newsgroup on the current line."
@@ -1791,7 +1785,7 @@ gnus-group-group-unread
 (defun gnus-group-new-mail (group)
   (if (nnmail-new-mail-p (gnus-group-real-name group))
       gnus-new-mail-mark
-    ? ))
+    ?\s))
 
 (defun gnus-group-level (group)
   "Return the estimated level of GROUP."
@@ -1881,7 +1875,7 @@ gnus-group-mark-group
 	(if unmark
 	    (progn
 	      (setq gnus-group-marked (delete group gnus-group-marked))
-	      (insert-char ? 1 t))
+              (insert-char ?\s 1 t))
 	   (setq gnus-group-marked
 		 (cons group (delete group gnus-group-marked)))
 	   (insert-char gnus-process-mark 1 t)))
@@ -2561,10 +2555,10 @@ gnus-group-goto-group
   (when group
     (let ((start (point))
 	  (active (and (or
-			;; some kind of group may be only there.
-			(gethash group gnus-active-hashtb)
-			;; all groups (but with exception) are there.
-			(gethash group gnus-newsrc-hashtb))
+                        ;; Some kind of group may be only there.
+                        (gnus-active group)
+                        ;; All groups (but with exception) are there.
+                        (gnus-group-entry group))
 		       group)))
       (beginning-of-line)
       (cond
@@ -4013,15 +4007,9 @@ gnus-group-list-active
 	  (gnus-agent gnus-plugged)); If we're actually plugged, store the active file in the agent.
       (gnus-read-active-file)))
   ;; Find all groups and sort them.
-  (let ((groups
-	 (sort
-	  (hash-table-keys gnus-active-hashtb)
-	  'string<))
-	(buffer-read-only nil)
-	group)
+  (let ((buffer-read-only nil))
     (erase-buffer)
-    (while groups
-      (setq group (pop groups))
+    (dolist (group (sort (hash-table-keys gnus-active-hashtb) #'string<))
       (add-text-properties
        (point) (prog1 (1+ (point))
 		 (insert "       *: "
-- 
2.20.1

While looking at bug#35208 and bug#35233, I spotted one more place in
gnus-group.el which sets the gnus-group text property to the group's
active info instead of its name, namely in
gnus-group-prepare-flat-list-dead.

Is the attached patch, which includes some extra cleanup, okay to push?
Or have I misunderstood something?

Thanks,

-- 
Basil