FindAdv: Significantly increase the search speed

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
This commit is contained in:
Kornel Benko 2018-11-13 12:11:33 +01:00
parent 1bdba953a5
commit 702c495e98

View 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) {