-if we have a match for a key, no other key can match
-match the start of a new line as QByteArray instead of QString, most lines will
not match and all keys are plain ASCII, this saves a lot of needless
conversions and memory allocations
-modify the original line instead of doing a copy, the original one will not
be used again anyway.
Details
Details
- Reviewers
mwolff - Commits
- R32:5bf2c3aae6ec: optimize CMakeBuildDirChooser::buildDirSettings()
Open and build a CMake-based project.
Diff Detail
Diff Detail
- Repository
- R32 KDevelop
- Branch
- cmutf8
- Lint
No Linters Available - Unit
No Unit Test Coverage - Build Status
Buildable 8547 Build 8565: arc lint + arc unit
Comment Actions
I wonder if that's actually faster. Here we are creating intermediary copies of the QByteArray only to convert to QString.
Comment Actions
The QByteArray was already created the same way, now the intermediate object is just cached. But even if that did not change anything it reduces the number of utf8 conversion as only those lines that actually match anything will be converted.
Comment Actions
No, I was just looking at it. I could remove the QByteArray change and reduce it to online the x.remove() and "else if" parts.
Comment Actions
using byte arrays is OK imo, but please cleanup the code overall by using a lambda instead of repeating the same thing over and over again
plugins/cmake/cmakebuilddirchooser.cpp | ||
---|---|---|
132 | const auto rawLine = ... | |
134 | introduce a helper lambda: auto match = [&rawLine](const QByteArray& prefix, QString* target) -> bool { if (line.startsWith(prefix) { *target = QString::formUtf8(line.constData() + prefix.size(), line.size() - prefix.size()); return true; } return false; }; use it: if (match(srcLine, &srcDir) || match(installLine, &installDir) || match(buildLine, &buildType)) { ++cnt; } |