Am Montag, 18. März 2013 um 14:01:44, schrieb Kornel Benko <[email protected]>
> The slowness in normal search part happens, because we have very inefficient
> algorithm.
> Suppose we have a string "This is a string." at the cursor position, and we
> search for "abcd".
> 
> The method MatchStringAdv::findAux() will be called now successively from 
> findForwardAdv()
> incrementing the cursor position.
> 
> In effect, we check whether following strings start with "abcd"
> 
> "This is a string."
> "his is a string."
> "is is a string."
> "s is a string."
> " is a string."
> "is a string."
> "s a string."
> ...
> 
> AT the first call, we already could know, the there is no "abcd" in the whole 
> string, therefore
> we need only to make findForwardAdv() notice it and increment the cursor 
> position accordingly.
> 
> The patch I attach her is a hack, I know. But at least it shows, that somehow 
> it should be possible.
> 
> With this patch the advanced search is about 50 times faster.
> Could someone with more knowledge create a proper solution?

It turns out, that this is already intended in the committed  stuff.

1.) match(cur, -1, false) tries to determine if the searched sub-string may be
        in the supplied DocIterator (lyxfind.cpp:914 ... )
2.) Only if yes, the following (slow) sequence of commands are executed.

BUT, the check id done against 'par_as_string_nolead', which in case of
opt.ignoreformat == true
is left empty.

This patch removes the slowness for me.

OK to commit?

        Kornel
diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp
index d6df0ef..80c0b3c 100644
--- a/src/lyxfind.cpp
+++ b/src/lyxfind.cpp
@@ -841,6 +841,9 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions const &
 	close_wildcards = 0;
 
 	size_t lead_size = 0;
+        // In case of ignore format it is othervise empty and
+        // will always *find* the string in the checked data
+        par_as_string_nolead = par_as_string;
 	if (!opt.ignoreformat) {
 		lead_size = identifyLeading(par_as_string);
 		lead_as_string = par_as_string.substr(0, lead_size);

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to