[Top][All Lists]

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

Re: find-file-noselect needs save-match-data

From: Miles Bader
Subject: Re: find-file-noselect needs save-match-data
Date: Thu, 14 Jun 2007 08:39:08 +0900

Richard Stallman <address@hidden> writes:
>     Anyway, such a function should likely _return_ the corresponding
>     match-data (rather than setting a global variable to it), and things
>     like match-beginning should optionally take an argument for this
>     particular match-data.
> That is a good idea.  If there is no match, it returns nil; if there
> is a match, it returns the match data.

One alternative to _returning_ the match data would be accepting an
argument -- a vector or list -- in which to _place_ the match data
(presumably this would be optional, and after the "normal" args).

This would have the advantage that it avoids consing the match-data
unless the user actually wants it, and yet remains convenient if the
user _does_ want it.


   (string-match-reentrant REGEXP STRING &optional START MATCH-DATA-VEC)

with usage like:

   (let ((mdata (vector 10)))
     (if (string-match-reentrant regexp string nil mdata)
         (message "blargh [%s] [%s]" (aref mdata 1) (aref mdata 2))))

[I'm not sure exactly the format of mdata; there'd have to be some sort
of accessor functions]

The disadvantage of this is that it would mean allocating the
return-vector every time the caller wants match-data, even if there ends
up being no match -- though often I guess this overhead could be reduced
when a piece of code can use the same vector for many different calls to

Which alternative better depends on the expected frequency of various
cases, but I think being able to easily avoid the allocation in the
extremely common "just match no data" case is valuable, so I'd tend to
think my above solution is preferable.


`Suppose Korea goes to the World Cup final against Japan and wins,' Moon said.
`All the past could be forgiven.'   [NYT]

reply via email to

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