D18857: optimize CMakeBuildDirChooser::buildDirSettings()

Milian Wolff noreply at phabricator.kde.org
Fri Feb 15 09:51:25 GMT 2019


mwolff requested changes to this revision.
mwolff added a comment.
This revision now requires changes to proceed.


  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

INLINE COMMENTS

> cmakebuilddirchooser.cpp:132
>      {
> -        // note: CMakeCache.txt is UTF8-encoded, also see bug 329305
> -        QString line = QString::fromUtf8(file.readLine().trimmed());
> +        QByteArray rawLine = file.readLine().trimmed();
>  

`const auto rawLine = ...`

> cmakebuilddirchooser.cpp:134
>  
> -        if (line.startsWith(srcLine))
> +        // note: CMakeCache.txt is UTF8-encoded, also see bug 329305
> +        if (rawLine.startsWith(srcLine))

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;
  }

REPOSITORY
  R32 KDevelop

REVISION DETAIL
  https://phabricator.kde.org/D18857

To: dakon, mwolff
Cc: mwolff, apol, kdevelop-devel, gennad, glebaccon, antismap, iodelay, alexeymin, geetamc, Pilzschaf, akshaydeo, surgenight, arrowd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20190215/2ac15265/attachment.html>


More information about the KDevelop-devel mailing list