Carsten Dominik ([EMAIL PROTECTED]) wrote: > On Jul 20, 2007, at 17:05, Adam Spiers wrote: > >On Wed, Jul 18, 2007 at 11:24:40PM +0200, Carsten Dominik wrote: > >>On Jul 16, 2007, at 15:21, Adam Spiers wrote: > >>>There seem to be a number of hardcoded regexps currently used for > >>>matching heading tags, all very similar looking, and typically > >>>something like: > >>> > >>> [ \t]*\\(:[[:alnum:]_@:]+:\\)?[ \t]*\\($\\|\r\\) > >>> > >>>Is there any reason why these shouldn't be factored out into a new > >>>defcustom org-tags-regexp? > >> > >>Well, one reason is efficiency. When a regular expression is a constant, > >>Emacs is able to cache the compiled version of the regular expression, > >>and this can speed up code that does a lot of matching quite a bit. > >>The token you show above is usually part of a larger string, so the full > >>regular expression would have to be make with concat and will therefore > >>be recompiled all the time. > > > >Right, point taken - like m//o in Perl. To be honest, it doesn't > >matter too much to me if it's defconst rather than defcustom. The > >main thing is that I can have tags starting with '<' :-) > > Hi Adam, > > this is not about defcustom or defconst, but about the question > of the regexp is built each time with concat, or not.
Ah, I was assuming that the elisp interpreter was intelligent enough that if you did a concat of two or more constants, it would only build the regexp the first time, similar to m//o in Perl. Is that not the case? Or maybe it only performs this optimisation if you byte-compile? I found this in the elisp manual: -- Special Form: eval-when-compile body... This form marks BODY to be evaluated at compile time but not when the compiled program is loaded. The result of evaluation by the compiler becomes a constant which appears in the compiled program. If you load the source file, rather than compiling it, BODY is evaluated normally. If you have a constant that needs some calculation to produce, `eval-when-compile' can do that at compile-time. For example, (defvar my-regexp (eval-when-compile (regexp-opt '("aaa" "aba" "abb")))) Maybe I should practice what I preach and use mercurial to start an experimental branch to look at the impact on performance of doing this refactoring :-) _______________________________________________ Emacs-orgmode mailing list Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode