[Top][All Lists]

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

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

From: martin rudalics
Subject: Re: find-file-noselect needs save-match-data
Date: Wed, 06 Jun 2007 08:57:27 +0200
User-agent: Mozilla Thunderbird 1.0 (Windows/20041206)

> No.  Most functions should not need to save-match-data (which is an
> expensive operation very rarely needed).  The place to save-match-data is
> typically on functions that use regexps and are placed on some sensitive
> hooks

... like when you put a function calling `find-file-noselect' or
`file-truename' on a sensitive hook.  You may have to look at the code
of each function on the entire call tree to detect whether one of them
might change match-data.  Since hardly anyone ever does that we'll have
to live with spurious, very hard-to-detect bugs clobbering match-data.
From the caller's point of view it's also hard to conceive why, for
example, the simpler `file-chase-links' does save match-data while the
more complicated `file-truename' doesn't.

The real problem is that most calls of `string-match' (and `looking-at')
don't make use of match-data anyway.  `file-truename', for example, has

        ((and (string= (substring filename 0 1) "~")
              (string-match "~[^/]*/?" filename))


          (unless (string-match "[[*?]" filename)
            ;; If filename exists, use the long name
            (setq filename (or (w32-long-file-name filename) filename))))

Both throw away match-data immediately.  If match-data is expensive why
build it in the first place when it's not needed?  Why not make a thing
like `fast-string-match' available in Lisp?

reply via email to

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