From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/69266 Path: news.gmane.org!not-for-mail From: Dan Christensen Newsgroups: gmane.emacs.gnus.general Subject: faster gnus-thread-latest-date Date: Mon, 07 Dec 2009 16:27:44 -0500 Message-ID: <87my1uiien.fsf@uwo.ca> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1260221345 3018 80.91.229.12 (7 Dec 2009 21:29:05 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 7 Dec 2009 21:29:05 +0000 (UTC) To: ding@gnus.org Original-X-From: ding-owner+M17671@lists.math.uh.edu Mon Dec 07 22:28:58 2009 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from util0.math.uh.edu ([129.7.128.18]) by lo.gmane.org with esmtp (Exim 4.50) id 1NHl8c-0005Le-Dr for ding-account@gmane.org; Mon, 07 Dec 2009 22:28:58 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by util0.math.uh.edu with smtp (Exim 4.63) (envelope-from ) id 1NHl7q-00042S-MX; Mon, 07 Dec 2009 15:28:10 -0600 Original-Received: from mx1.math.uh.edu ([129.7.128.32]) by util0.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1NHl7p-00042E-BZ for ding@lists.math.uh.edu; Mon, 07 Dec 2009 15:28:09 -0600 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx1.math.uh.edu with esmtp (Exim 4.69) (envelope-from ) id 1NHl7n-0003zm-Vz for ding@lists.math.uh.edu; Mon, 07 Dec 2009 15:28:09 -0600 Original-Received: from lo.gmane.org ([80.91.229.12]) by quimby.gnus.org with esmtp (Exim 3.36 #1 (Debian)) id 1NHl7n-0002yk-00 for ; Mon, 07 Dec 2009 22:28:07 +0100 Original-Received: from list by lo.gmane.org with local (Exim 4.50) id 1NHl7m-0004zz-5a for ding@gnus.org; Mon, 07 Dec 2009 22:28:06 +0100 Original-Received: from bas3-london14-1096778571.dsl.bell.ca ([65.95.131.75]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 07 Dec 2009 22:28:06 +0100 Original-Received: from jdc by bas3-london14-1096778571.dsl.bell.ca with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 07 Dec 2009 22:28:06 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 46 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: bas3-london14-1096778571.dsl.bell.ca User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.1.50 (gnu/linux) Cancel-Lock: sha1:xIfN1QqAtHnjqu+jxHXDg48eyFM= X-Spam-Score: -2.6 (--) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:69266 Archived-At: The function gnus-thread-latest-date is used by gnus-thread-sort-by-most-recent-date, and is very slow. The current code is: (defun gnus-thread-latest-date (thread) "Return the highest article date in THREAD." (let ((previous-time 0)) (apply 'max (mapcar (lambda (header) (setq previous-time (condition-case () (gnus-float-time (mail-header-parse-date (mail-header-date header))) (error previous-time)))) (sort (message-flatten-list thread) (lambda (h1 h2) (< (mail-header-number h1) (mail-header-number h2)))))))) Since all that is desired is the latest date, I don't see why dates that don't parse are replaced by the date of the article with the previous number. Why not just replace them with zero? And if you do that, then there is no need for a preliminary sort by number. So I think the following version should produce identical output: (defun gnus-thread-latest-date (thread) "Return the highest article date in THREAD." (apply 'max (mapcar (lambda (header) (condition-case () (gnus-float-time (mail-header-parse-date (mail-header-date header))) (error 0))) (message-flatten-list thread)))) Can someone check my logic? In my tests, it is noticeable faster. Can it be improved further? I have papers on file for Gnus and Emacs, so feel free to apply this change. Dan