Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 4502A431FBC for ; Mon, 5 Mar 2012 07:23:23 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8cva7FRuGbw1 for ; Mon, 5 Mar 2012 07:23:22 -0800 (PST) Received: from guru.guru-group.fi (guru-group.fi [87.108.86.66]) by olra.theworths.org (Postfix) with ESMTP id EF853431FAE for ; Mon, 5 Mar 2012 07:23:21 -0800 (PST) Received: by guru.guru-group.fi (Postfix, from userid 501) id 64C0768055; Mon, 5 Mar 2012 17:23:20 +0200 (EET) From: Tomi Ollila To: Daniel Schoepe , Dmitry Kurochkin , notmuch@notmuchmail.org Subject: Re: [PATCH v2] emacs: Pass a copy to notmuch-saved-search-sort-function In-Reply-To: <87399n2t60.fsf@schoepe.localhost> References: <1330613059-5130-1-git-send-email-daniel@schoepe.org> <1330633478-1974-1-git-send-email-daniel@schoepe.org> <1330633478-1974-2-git-send-email-daniel@schoepe.org> <87booblrcv.fsf@gmail.com> <87399n2t60.fsf@schoepe.localhost> User-Agent: Notmuch/0.11.1+288~g4b3af0e (http://notmuchmail.org) Emacs/23.3.1 (x86_64-unknown-linux-gnu) X-Face: HhBM'cA~ MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Mar 2012 15:23:23 -0000 On Mon, 05 Mar 2012 12:17:43 +0100, Daniel Schoepe wrote: > On Mon, 05 Mar 2012 06:21:52 +0400, Dmitry Kurochkin wrote: > > On Thu, 1 Mar 2012 21:24:38 +0100, Daniel Schoepe wrote: > > > notmuch-saved-search-sort-function might destructively modify its > > > input (`sort' does that, for instance), so it should not be given > > > notmuch-saved-searches directly. > > > --- > > > > -1 > > > > I think we should require `notmuch-saved-search-sort-function' not to > > have side effects. Current documentation should be more clear about > > this. We need to fix `notmuch-sort-saved-searches' to copy the list > > before calling `sort'. But we should not do it in > > `notmuch-hello-insert-saved-searches' for any sorting function (which > > may not need this copying). > > My reasoning was that since sort is such a common function, many users > will probably use sort for their own sorting functions, not realizing > that it has side effects. This will lead to confusing behavior that's > not so easy to track down. > > Copying the list of saved searches when running notmuch-hello does not > seem be relevant to performance to me, since it's a) not called that > often and b) the list of saved searches will rarely exceed 30 elements. > > Hence, this way we can avoid some headaches for users who define their > own sorting functions at a negligible (performance) cost. Incidentally, > this is also how notmuch-hello did it before the user-defined sections > patches. Hard to say -- maybe the alternative: (defun notmuch-sort-saved-searches (alist) "Generate an alphabetically sorted saved searches alist." - (sort alist (lambda (a b) (string< (car a) (car b))))) + (sort (copy-sequence alist) (lambda (a b) (string< (car a) (car b))))) matches better with the current documentation (of notmuch-saved-search-sort-function). Both sort and copy-sequence are blazingly fast... For more information, read http://www.emacswiki.org/emacs/DestructiveOperations > Cheers, > Daniel Tomi