From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.emacs.devel Subject: Re: Inefficient code in reftex-index.el Date: Thu, 09 Jun 2005 17:05:19 +0200 Message-ID: <853brr605s.fsf@lola.goethe.zz> References: <85slzv7j87.fsf@lola.goethe.zz> <858y1n2g75.fsf@lola.goethe.zz> <85oeai1pwq.fsf@lola.goethe.zz> <878y1mkpy3.fsf-monnier+emacs@gnu.org> <85ekbc6cje.fsf@lola.goethe.zz> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1118331760 1839 80.91.229.2 (9 Jun 2005 15:42:40 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 9 Jun 2005 15:42:40 +0000 (UTC) Cc: emacs-devel@gnu.org, monnier@iro.umontreal.ca, storm@cua.dk, dominik@science.uva.nl Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jun 09 17:42:29 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DgP4q-0006u1-Ls for ged-emacs-devel@m.gmane.org; Thu, 09 Jun 2005 17:36:17 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DgPBn-0001Ae-A5 for ged-emacs-devel@m.gmane.org; Thu, 09 Jun 2005 11:43:27 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DgP9e-0000Qy-2R for emacs-devel@gnu.org; Thu, 09 Jun 2005 11:41:14 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DgP9d-0000QW-11 for emacs-devel@gnu.org; Thu, 09 Jun 2005 11:41:13 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DgP4j-0006kq-7R for emacs-devel@gnu.org; Thu, 09 Jun 2005 11:36:09 -0400 Original-Received: from [199.232.76.164] (helo=fencepost.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DgObn-0004Ct-O0 for emacs-devel@gnu.org; Thu, 09 Jun 2005 11:06:15 -0400 Original-Received: from localhost ([127.0.0.1] helo=lola.goethe.zz) by fencepost.gnu.org with esmtp (Exim 4.34) id 1DgOaq-0003Te-8J; Thu, 09 Jun 2005 11:05:20 -0400 Original-Received: by lola.goethe.zz (Postfix, from userid 1002) id 4B2FC1C15385; Thu, 9 Jun 2005 17:05:20 +0200 (CEST) Original-To: rms@gnu.org In-Reply-To: (Richard Stallman's message of "Thu, 09 Jun 2005 10:40:19 -0400") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:38449 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:38449 Richard Stallman writes: > > Can't you tell that more easily by seeing if match-beginning returns nil? > > Which match-beginning? > > One for a subexpression inside the alternative you're trying to test for. > > After (string-match "\\(a\\)\\|\\(b\\)\\|\\(c\\)" input) > > I can just consult (length (match-data)) for distinguishing between > all three alternatives. > > You could, but you'd have to compare the value of that against > various constants, which would be ugly. Uh, no. In the applications I am using, the expression for the string match is created programmatically from a large list of strings, and the result is used for indexing into corresponding data structures. > I think this code is cleaner: > > (cond ((match-beginning 1) > ...) > ((match-beginning 2) > ...) > ((match-beginning 3) > ...) Certainly cleaner than the straw man you are trying to put up, no question about that. And I have been using this idiom a number of times for other code. In the application that I had in mind, however, no different code paths were taken, and so this boiled down to (while (not (match-beginning index)) (setq index (1+ index))) (do-something-about index) -- David Kastrup, Kriemhildstr. 15, 44793 Bochum