]> git.lyx.org Git - features.git/commitdiff
FindAdv: Significantly increase the search speed
authorKornel Benko <kornel@lyx.org>
Tue, 13 Nov 2018 11:11:33 +0000 (12:11 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 12:39:51 +0000 (14:39 +0200)
The needed time to find a simple string dependes on the
paragraph length was O(n^2)
Now it is down to O(n).
Before:
To determine if the pattern matches we compared the
paragraph from current position to the its end.
Increment current position if no match
Now:
Check if the character at current position has at least
the needed features (text, color, language etc)
If not, Increment current position
else proceed as before

src/lyxfind.cpp

index 6cc57f49160aae6d3a90c102915f13c641300a16..2fd36e289e1ea537f85356b7481c31bd5d688bbe 100644 (file)
@@ -1630,7 +1630,7 @@ void LatexInfo::buildKeys(bool isPatternString)
   // No split
   makeKey("backslash|textbackslash|textasciicircum|textasciitilde|ldots", KeyInfo(KeyInfo::isChar, 1, false), isPatternString);
   // Found in fr/UserGuide.lyx
-  makeKey("og|fg", KeyInfo(KeyInfo::isChar, 0, false), isPatternString);
+  makeKey("og|fg|textvisiblespace", KeyInfo(KeyInfo::isChar, 0, false), isPatternString);
 
   // Known macros to remove (including their parameter)
   // No split
@@ -2281,6 +2281,8 @@ static int computeSize(string s, int len)
                                                        skip++;
                                                else if ((s[i+j] == '{') && s[i+j+1] == '}')
                                                        skip += 2;
+                                               else if ((s[i+j] == '{') && (i + j + 1 >= len))
+                                                       skip++;
                                                break;
                                        }
                                        skip++;
@@ -2693,6 +2695,9 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv & match)
                        int match_len_zero_count = 0;
                        for (; !theApp()->longOperationCancelled() && cur; cur.forwardPos()) {
                                LYXERR(Debug::FIND, "Advancing cur: " << cur);
+                               int match_len3 = match(cur, 1);
+                               if (match_len3 < 0)
+                                       continue;
                                int match_len2 = match(cur);
                                LYXERR(Debug::FIND, "match_len2: " << match_len2);
                                if (match_len2 > 0) {