[kde-edu]: Review Request: Syntax Hightlighting in Cantor

Miha Cancula miha.cancula at gmail.com
Tue Aug 24 21:44:58 CEST 2010

This is an automatically generated e-mail. To reply, visit:

(Updated 2010-08-24 19:44:58.040361)

Review request for KDE-Edu and Alexander Rieder.


About the iteration: I like foreach because it looks cleaner, but I remember an article on PlanetKDE that an integer for-loop is the fastest. OTOH, it's referenced four times, so maybe the operator[] calls even it out. Anyway, I think that iteration isn't the bottleneck, regex matching is. So cleaner code it is.

The rest I fixed. If there's more typos, I will check for them on EBN.  

I don't think any new kDebug() statements should be there, because it makes debugging backends harder. 


As discussed on email, I implemented a different approach to highlighting in Cantor. I'd like some feedback before committing it. 

I introduced additional API in DefaultHighlighter and moved most of the logic in it, so the individual backend-specific highlighters only specify conditions (either QString or QRegExp) and matching text formats. The code looks much cleaner this way.

As Alexander and Oleksiy already determined, breaking the text into words and looking for these words is faster than iterating over a huge list of regexes and looking for each of them in the text. That's why functions, variables and keywords are implemented this way. OTOH, thing like comments and strings are easier done using Regexes, so this functionality is still there.  

The implementation uses a QHash<QString, QTextCharFormat> and a QHash<QRegExp, QTextCharFormat>. If anyone knows of a way to make it faster, please say so. 

I also updated highlighters for Octave, Maxima and Sage to use the word-based API as much as possible. Most of their code was also removed, because it's now in DefaultHighlighter. I left R alone because Oleksiy's work is not yet in trunk. 

Diffs (updated)

  /trunk/KDE/kdeedu/cantor/src/backends/maxima/maximahighlighter.h 1166762 
  /trunk/KDE/kdeedu/cantor/src/backends/maxima/maximahighlighter.cpp 1166762 
  /trunk/KDE/kdeedu/cantor/src/backends/octave/octavehighlighter.h 1166762 
  /trunk/KDE/kdeedu/cantor/src/backends/octave/octavehighlighter.cpp 1166762 
  /trunk/KDE/kdeedu/cantor/src/backends/sage/sagehighlighter.h 1166762 
  /trunk/KDE/kdeedu/cantor/src/backends/sage/sagehighlighter.cpp 1166762 
  /trunk/KDE/kdeedu/cantor/src/lib/defaulthighlighter.h 1166762 
  /trunk/KDE/kdeedu/cantor/src/lib/defaulthighlighter.cpp 1166762 

Diff: http://reviewboard.kde.org/r/5079/diff


I tested Maxima and Sage and they seem to be faster than before for large blocks. I used to have problems with non-smooth scrolling in Octave due to the large number of functions, but now it feels normal. I didn't notice any regressions (yet). 

It all works both on trunk and 4.4.  



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.kde.org/pipermail/kde-edu/attachments/20100824/7071d0e0/attachment.htm 

More information about the kde-edu mailing list