[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Compiled regexp?
From: |
Dominik, Carsten |
Subject: |
Re: Compiled regexp? |
Date: |
Thu, 31 Jan 2013 15:34:49 +0000 |
On 31 jan. 2013, at 16:28, Stefan Monnier <address@hidden>
wrote:
>> ;; Concat in defconst
>> (defconst my-pattern (concat "^" "xyz"))
>> (re-search-forward my-pattern ...)
> -vs-
>> ;; Concat in re-search-forward
>> (defconst my-partial-pattern "xyz")
>> (re-search-forward (concat "^" my-partial-pattern) ...)
> [...]
>> Can anyone confirm this is the case?
>
> The second will incur the additional cost of the `concat' at each
> iteration, obviously, but other than that the current Emacs code will
> not take advantage of the fact that the same string is passed in the
> first code, whereas a new string is use in the second.
OK, this is clear, thank you very much.
- Carsten
>
> I don't forsee the Emacs code changing such that it's significantly more
> efficient to reuse the exact same string rather than a copy of it.
>
> If we ever try to do something to avoid the cost of re-compiling
> a regexp, I'd expect that we'd provide a way to have explicit access to
> compiled regexps (with a `regexp-compile' function, the result of which
> would be accepted by re-search-forward as an alternative to a string).
>
>
> Stefan "Who generally prefers the first form"