emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Inefficient code in reftex-index.el


From: David Kastrup
Subject: Re: Inefficient code in reftex-index.el
Date: Thu, 09 Jun 2005 17:05:19 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

Richard Stallman <address@hidden> 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]