[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Compiled regexp?
From: |
Andreas Schwab |
Subject: |
Re: Compiled regexp? |
Date: |
Thu, 31 Jan 2013 15:26:24 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.2.92 (gnu/linux) |
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.
The first pattern evaluates (concat "^" "xyz") once when my-pattern is
defined. The second case evalutes (concat "^" my-partial-pattern) each
time the containing sexp is evaluated. Other than that there is no
difference wrt. re-search-forward.
Andreas.
--
Andreas Schwab, address@hidden
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."