Subject: Re: bug#16800: 24.3; flyspell works slow on very short words at the end of big file

From: Aleksey Cherepanov <[email-masked]>
Date: Mon, 24 Feb 2014 00:39:58 +0400

On Sun, Feb 23, 2014 at 02:26:00AM +0100, Agustin Martin wrote:
> --- flyspell.el.orig	2014-02-23 02:17:03.680107519 +0100
> +++ flyspell.el	2014-02-23 02:50:50.634625248 +0100
> @@ -1050,8 +1050,19 @@
>    (save-excursion
>      (let ((r '())
>  	  (inhibit-point-motion-hooks t)
> +	  (flyspell-not-casechars (flyspell-get-not-casechars))
>  	  p)
> -      (while (and (not r) (setq p (search-backward word bound t)))
> +      (while 
> +	  (and (not r) 
> +	       (setq p 
> +		     (re-search-backward
> +		      (concat
> +		       "\\(" flyspell-not-casechars "\\|\\b\\)"
> +		       "\\(" word "\\)"
> +		       flyspell-not-casechars
> +		       )
> +		      bound t)))
> +	(goto-char (match-beginning 2))

I am not yet sure that it is important. But as written we store
position - 1 instead of position if we matched with
flyspell-not-casechars branch. (goto-char ...) could be placed
inside (setq p ...) to fix it:
(setq p
      (and
        (re-search ...)
        (goto-char ...)))
I do not know real difference yet though.

Respectively we store position + 1 in forward search.

Thanks!

-- 
Regards,
Aleksey Cherepanov