help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: `looking-back' strange warning


From: Tassilo Horn
Subject: Re: `looking-back' strange warning
Date: Fri, 02 Oct 2015 17:21:23 +0200
User-agent: Gnus/5.130014 (Ma Gnus v0.14) Emacs/25.0.50 (gnu/linux)

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> `re-search-backward' already slow without LIMIT?
>
> Note that re-search-* performs a *search* whereas looking-at (and
> looking-back) perform a *match*, which is expected to be quicker.
>
> re-search-* is implemented by performing a *match* at every position
> and stop at the first where a match is encountered.

I see, so

  (looking-back "foobar")

will call

  (re-search-backward "\\(?:foobar\\)\\=")

which in turn will at best (if point is just right of a foobar
occurrence) move point backwards 6 times and perform a match each time.
In the worst case (if we're not right of a foobar occurrence) point
moves until (or LIMIT (point-min)) trying a match each time.  So yes, I
now get that `looking-back' is slow especially when no LIMIT near is
given.

And the extension if GREEDY is t is pretty much the same as what
`re-search-*' does too (but of course in C), right?  (But that
`looking-back' concats the regex each while iteration is needless
effort.)

Bye,
Tassilo



reply via email to

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