Subject: Replace gnus-last-element with car->last

From: Eric Abrahamsen <[email-masked]>
Date: Sun, 15 Oct 2017 21:07:42 -0700

(car (last LIST)) does just what (gnus-last-element LIST) does, and is
considerably more efficient.

I think this is fairly uncontroversial, but will let it hang out a bit
first in case anyone sees something I don't.

>From 63251a3248569df0fde85f52e3ce1f605e0c3b3a Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <[email-masked]>
Date: Tue, 9 May 2017 18:48:00 +0800
Subject: [PATCH] Remove gnus-last-element

* lisp/gnus/gnus-range.el: Now better expressed as (car (last LIST)).
* lisp/gnus/gnus-cache.el (gnus-cache-generate-active):
* lisp/gnus/gnus-sum.el (gnus-select-newsgroup,
  gnus-summary-insert-articles): Replace calls.
---
 lisp/gnus/gnus-cache.el | 2 +-
 lisp/gnus/gnus-range.el | 6 ------
 lisp/gnus/gnus-sum.el   | 4 ++--
 3 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/lisp/gnus/gnus-cache.el b/lisp/gnus/gnus-cache.el
index 12c8903d02..801728d2f2 100644
--- a/lisp/gnus/gnus-cache.el
+++ b/lisp/gnus/gnus-cache.el
@@ -735,7 +735,7 @@ gnus-cache-generate-active
       ;; `gnus-cache-unified-group-names' needless.
       (gnus-sethash (or (cdr (assoc group gnus-cache-unified-group-names))
 			group)
-		    (cons (car nums) (gnus-last-element nums))
+		    (cons (car nums) (car (last nums)))
 		    gnus-cache-active-hashtb))
     ;; Go through all the other files.
     (dolist (file alphs)
diff --git a/lisp/gnus/gnus-range.el b/lisp/gnus/gnus-range.el
index b30b2e9099..3c84f9d69a 100644
--- a/lisp/gnus/gnus-range.el
+++ b/lisp/gnus/gnus-range.el
@@ -33,12 +33,6 @@ gnus-range-normalize
 If RANGE is a single range, return (RANGE). Otherwise, return RANGE."
   (if (listp (cdr-safe range)) range (list range)))
 
-(defun gnus-last-element (list)
-  "Return last element of LIST."
-  (while (cdr list)
-    (setq list (cdr list)))
-  (car list))
-
 (defun gnus-copy-sequence (list)
   "Do a complete, total copy of a list."
   (let (out)
diff --git a/lisp/gnus/gnus-sum.el b/lisp/gnus/gnus-sum.el
index 48571096cc..22160e4142 100644
--- a/lisp/gnus/gnus-sum.el
+++ b/lisp/gnus/gnus-sum.el
@@ -5737,7 +5737,7 @@ gnus-select-newsgroup
 	      (mail-header-number (car gnus-newsgroup-headers))
 	      gnus-newsgroup-end
 	      (mail-header-number
-	       (gnus-last-element gnus-newsgroup-headers))))
+	       (car (last gnus-newsgroup-headers)))))
       ;; GROUP is successfully selected.
       (or gnus-newsgroup-headers t)))))
 
@@ -12915,7 +12915,7 @@ gnus-summary-insert-articles
 	    (mail-header-number (car gnus-newsgroup-headers))
 	    gnus-newsgroup-end
 	    (mail-header-number
-	     (gnus-last-element gnus-newsgroup-headers))))
+	     (car (last gnus-newsgroup-headers)))))
     (when gnus-use-scoring
       (gnus-possibly-score-headers))))
 
-- 
2.14.2