[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Compiled regexp?
From: |
Stefan Monnier |
Subject: |
Re: Compiled regexp? |
Date: |
Thu, 31 Jan 2013 10:28:05 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
> ;; 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.
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"