[Interest] Highlighting: huge rule numbers [hang app]

Yves Bailly yves.bailly at sescoi.fr
Mon Jun 10 11:32:56 CEST 2013


Le 05/06/2013 15:32, Sensei a écrit :
> Hi! I am trying to find the limits of the syntax highlighter example.
>
> I am adding rules that begin with "\", but when I hit the backslash, my
> application starts to show the threatening spin wheel of death... and I
> obviously need to kill it.
>
> At the bottom you will see the code where, after killing the program,
> the debugger says it stopped.
>
> My rules are ~5000.
>
> Is there any "smart" way of handling this large number of rules?
>
>       foreach (const HighlightingRule &rule, highlightingRules) {
>           QRegExp expression(rule.pattern);
>           int index = expression.indexIn(text);

First, avoid creating again and again the QRegExp instance, it's rather costly.
Your "HighlightingRule" type seems to be some kind of struct, in which "pattern"
is a QString: store the QRegExp instead of the QString.

Second, maybe try to group rules. For example, instead of rules like
\some
\words
\list
...try defining a rule like
\(some|words|list)
...then the regex will extract the word, which can then be used as index in
some QHash-like dictionnary, e.g. QHash<QString, QTextCharFormat>. Overall
this lessen the number of regex processing, which should help.

Just some quick ideas, hope this helps.

-- 
      /- Yves Bailly - Software developer   -\
      \- Sescoi R&D  - http://www.sescoi.fr -/
"The possible is done. The impossible is being done. For miracles,
thanks to allow a little delay."



More information about the Interest mailing list