[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: `looking-back' strange warning
From: |
Drew Adams |
Subject: |
RE: `looking-back' strange warning |
Date: |
Fri, 2 Oct 2015 13:28:15 -0700 (PDT) |
> > My two cents: Even if you specify an optimal limit, `looking-back' can
> > still be unnecessarily slow. For example,
> > (looking-back "xy" 2)
> > is much slower than
> > (and (> (point) 2)
> > (save-excursion (goto-char (- (point) 2))
> > (looking-at "xy")))
> > where "xy" stands for any plain string.
>
> Definitely. And this is in fact a typical case of the
> misuse: the string to check is often a literal, so its
> length is known.
>
> This is the first thing to mention about `looking-back',
> in terms of performance: avoid it altogether, if you can.
BTW/FWIW -
I use this function in such cases, which can be pretty common:
(defun chars-before (chars)
"Return non-nil if the literal string CHARS is right before point.
This is more efficient that `looking-back' for this use case."
(let* ((len (length chars))
(idx (1- len))
(pt (point)))
(catch 'chars-before
(dolist (char (append chars ()))
(unless (condition-case nil
(eq char (char-before (- pt idx)))
(error nil)) ; e.g. `bobp'
(throw 'chars-before nil))
(setq idx (1- idx)))
t)))
http://www.emacswiki.org/emacs/download/misc-fns.el
- Re: `looking-back' strange warning, (continued)
- RE: `looking-back' strange warning, Drew Adams, 2015/10/08
- Re: `looking-back' strange warning, Dmitry Gutov, 2015/10/08
- Re: `looking-back' strange warning, Andreas Röhler, 2015/10/08
- Re: `looking-back' strange warning, Dmitry Gutov, 2015/10/08
- Re: `looking-back' strange warning, Andreas Röhler, 2015/10/08
- Re: `looking-back' strange warning, Stefan Monnier, 2015/10/08
- Re: `looking-back' strange warning, Michael Heerdegen, 2015/10/08
- Re: `looking-back' strange warning, Michael Heerdegen, 2015/10/08
- RE: `looking-back' strange warning, Drew Adams, 2015/10/08
- RE: `looking-back' strange warning,
Drew Adams <=
- Re: `looking-back' strange warning, Tassilo Horn, 2015/10/08
- RE: `looking-back' strange warning, Drew Adams, 2015/10/08
- Re: `looking-back' strange warning, Tassilo Horn, 2015/10/08
- RE: `looking-back' strange warning, Drew Adams, 2015/10/08
- Re: `looking-back' strange warning, Andreas Röhler, 2015/10/08
- RE: `looking-back' strange warning, Drew Adams, 2015/10/08
- RE: `looking-back' strange warning, Drew Adams, 2015/10/08
- Re: `looking-back' strange warning, Andreas Röhler, 2015/10/08
- Re: `looking-back' strange warning, Michael Heerdegen, 2015/10/08
- Re: `looking-back' strange warning, Stefan Monnier, 2015/10/08