Make Plasma::Svg::elementRect a bit leaner
ClosedPublic

Authored by apol on Jun 13 2019, 6:42 PM.

Details

Summary

Don't double-access maps
Don't construct ids more times than necessary.
Make regular expression static so it's not compiled on every run.
Remove unused code.

Diff Detail

Repository
R242 Plasma Framework (Library)
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
apol created this revision.Jun 13 2019, 6:42 PM
Restricted Application added a project: Frameworks. · View Herald TranscriptJun 13 2019, 6:42 PM
Restricted Application added a subscriber: kde-frameworks-devel. · View Herald Transcript
apol requested review of this revision.Jun 13 2019, 6:42 PM
bruns added a subscriber: bruns.Jun 13 2019, 11:15 PM

Please put the dead code removal in a separate review.

src/plasma/svg.cpp
121–122

Please use a QRegularExpression with lazy quantifiers, you can use const static then, no need for QRegExp.setMinimal(true).
Just replace */+ with *?/+?.

apol updated this revision to Diff 59772.Jun 13 2019, 11:56 PM

Prefer a QRegularExpression to QRegExp

bruns added inline comments.Jun 14 2019, 12:05 PM
src/plasma/svg.cpp
123

Are you sure you uploaded the right diff? No const static, Q_ASSERT ...

apol marked an inline comment as done.Jun 14 2019, 12:54 PM
apol added inline comments.
src/plasma/svg.cpp
123

static isn't necessary, QRegularExpression already has internal regex compilation optimisations we can leverage.
Does the assert bother you?

bruns added inline comments.Jun 14 2019, 1:27 PM
src/plasma/svg.cpp
123

Are you sure about this? As far as I can see:

QRegularExpression::QRegularExpression(QString pattern) default constructs a QRegularExpressionPrivate, which sets dirty(true).

Calling QRE::globalMatch() calls QREPrivate::compilePattern, which calls pcre2_compile_16 and pcre2_jit_compile_16.

https://code.woboq.org/qt5/qtbase/src/corelib/tools/qregularexpression.cpp.html#_ZN25QRegularExpressionPrivate14compilePatternEv

I don't see any caching here.

apol added inline comments.Jun 14 2019, 2:25 PM
src/plasma/svg.cpp
123

pcre2 does it, AFAIK.

bruns added inline comments.Jun 14 2019, 11:02 PM
src/plasma/svg.cpp
123

Benchmark tells const static is faster:

apol updated this revision to Diff 59837.Jun 14 2019, 11:23 PM

static const to be sure that QRegularExpression is only initialised once

apol marked an inline comment as done.Jun 14 2019, 11:24 PM
davidedmundson accepted this revision.Jun 21 2019, 1:24 PM
This revision is now accepted and ready to land.Jun 21 2019, 1:24 PM
This revision was automatically updated to reflect the committed changes.