emacs-devel
[Top][All Lists]
Advanced

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

Re: Compiled regexp?


From: Christopher Schmidt
Subject: Re: Compiled regexp?
Date: Thu, 31 Jan 2013 14:08:02 +0000 (GMT)

Bastien <address@hidden> writes:
> After Christopher submitted a patch for org-mode, Carsten and him
> discussed the difference between these two patterns:
>
>   ;; Concat in defconst
>   (defconst my-pattern (concat "^" "xyz"))
>   (re-search-forward my-pattern ...)
>
>   ;; Concat in re-search-forward
>   (defconst my-partial-pattern "xyz")
>   (re-search-forward (concat "^" my-partial-pattern) ...)
>
> Both Carsten and I thought there was some optimization done
> by Emacs so that the first pattern is more efficient than the
> second one.  (concat "^" "xyz") would be "cached", not eval'ed
> each time you search for my-pattern.

No, this is not what we discussed.  re-search-forward is a regular
function and eval'ing (re-search-forward (concat "^" my-partial-pattern)
...) will result in concat being eval'ed, too.  The overhead is
negligible, though.

We discussed how cached compiled regexps are looked up, i.e. per object
or per content.  If the former were true, (re-search-forward (concat "^"
my-partial-pattern) ...) would result in the regular expression being
compiled each and every time because concat returns a new lisp object.
That's slow.

I pointed out that this is does not look meaningful to me.  Ultimately I
took a glimpse at the code.  compile_pattern in search.c compares
the regexps using Fstring_equal.

        Christopher



reply via email to

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