D28039: optimize dynamic regex matching
This revision was automatically updated to reflect the committed changes. Closed by commit R216:764957b1d23c: optimize dynamic regex matching (authored by cullmann). REPOSITORY R216 Syntax Highlighting CHANGES SINCE LAST UPDATE https://phabricator.kde.org/D28039?vs=77593&id=77613 REVISION DETAIL https://phabricator.kde.org/D28039 AFFECTED FILES src/lib/abstracthighlighter.cpp src/lib/rule.cpp src/lib/rule_p.h To: cullmann, dhaumann, vkrause, nibags Cc: mwolff, kwrite-devel, kde-frameworks-devel, rrosch, LeGast00n, cblack, GB_2, domson, michaelh, ngraham, bruns, demsking, cullmann, sars, dhaumann
D28039: optimize dynamic regex matching
cullmann added a comment. First let's have this, the current state is bad ;=) INLINE COMMENTS > dhaumann wrote in rule_p.h:126 > I dislike this protected hack :-) That is called inheritance ;=) I first had a virtual function, but this is much easier and faster. (and just costs a few bytes) REPOSITORY R216 Syntax Highlighting BRANCH master REVISION DETAIL https://phabricator.kde.org/D28039 To: cullmann, dhaumann, vkrause, nibags Cc: mwolff, kwrite-devel, kde-frameworks-devel, rrosch, LeGast00n, cblack, GB_2, domson, michaelh, ngraham, bruns, demsking, cullmann, sars, dhaumann
D28039: optimize dynamic regex matching
dhaumann added a comment. Thanks yes, maybe you can add a comment to the skipOffset, Christoph :) REPOSITORY R216 Syntax Highlighting BRANCH master REVISION DETAIL https://phabricator.kde.org/D28039 To: cullmann, dhaumann, vkrause, nibags Cc: mwolff, kwrite-devel, kde-frameworks-devel, rrosch, LeGast00n, cblack, GB_2, domson, michaelh, ngraham, bruns, demsking, cullmann, sars, dhaumann
D28039: optimize dynamic regex matching
mwolff added a comment. Let me try to explain the skip offset idea (it's been years since I came up with this in GeSHi :) ) A code highlighter will repeatedly ask all highlight contexts and items therein to find the closest token to highlight next to the current cursor position. The closest token will win and then the highlighter will repeat its question at the position after the token. For regular expressions, it's often cheaper (as indicated by this patch once again), to match the line once starting from the current position and then remember where the first match - if any - is in the current line. Then, the next time the highlighter asks for a token position, we can check the last matched position. This is essentially the skip offset - i.e. we know that we can skip querying the regexp again until the cursor position is beyond the next match. Dominik, does this clear things up? REPOSITORY R216 Syntax Highlighting BRANCH master REVISION DETAIL https://phabricator.kde.org/D28039 To: cullmann, dhaumann, vkrause, nibags Cc: mwolff, kwrite-devel, kde-frameworks-devel, rrosch, LeGast00n, cblack, GB_2, domson, michaelh, ngraham, bruns, demsking, cullmann, sars, dhaumann
D28039: optimize dynamic regex matching
dhaumann accepted this revision. dhaumann added a comment. This revision is now accepted and ready to land. I guess this is OK, but the concept of a "skip offset" is a bit fuzzy to me. INLINE COMMENTS > rule_p.h:126 > + > +protected: > +bool m_dynamic = false; I dislike this protected hack :-) REPOSITORY R216 Syntax Highlighting BRANCH master REVISION DETAIL https://phabricator.kde.org/D28039 To: cullmann, dhaumann, vkrause, nibags Cc: kwrite-devel, kde-frameworks-devel, rrosch, LeGast00n, cblack, GB_2, domson, michaelh, ngraham, bruns, demsking, cullmann, sars, dhaumann
D28039: optimize dynamic regex matching
cullmann added a comment. For the example from the bug this makes the difference between ~30 seconds on a 4 Ghz machine to << 1 second ;=) REPOSITORY R216 Syntax Highlighting REVISION DETAIL https://phabricator.kde.org/D28039 To: cullmann, dhaumann, vkrause, nibags Cc: kwrite-devel, kde-frameworks-devel, rrosch, LeGast00n, cblack, GB_2, domson, michaelh, ngraham, bruns, demsking, cullmann, sars, dhaumann
D28039: optimize dynamic regex matching
cullmann created this revision. cullmann added reviewers: dhaumann, vkrause, nibags. Herald added projects: Kate, Frameworks. Herald added subscribers: kde-frameworks-devel, kwrite-devel. cullmann requested review of this revision. REVISION SUMMARY allow such matches to be cached, too, by guarding the cache with the last used captures makes VHDL highlighting instantanious for bug 418778 BUG: 418778 TEST PLAN make && make test example from bug 418778 is fast! REPOSITORY R216 Syntax Highlighting BRANCH master REVISION DETAIL https://phabricator.kde.org/D28039 AFFECTED FILES src/lib/abstracthighlighter.cpp src/lib/rule.cpp src/lib/rule_p.h To: cullmann, dhaumann, vkrause, nibags Cc: kwrite-devel, kde-frameworks-devel, rrosch, LeGast00n, cblack, GB_2, domson, michaelh, ngraham, bruns, demsking, cullmann, sars, dhaumann