D8536: Add more hashing algorithms to KPropertiesDialog

Anthony Fieroni noreply at phabricator.kde.org
Wed Dec 27 09:26:17 UTC 2017


anthonyfieroni added inline comments.

INLINE COMMENTS

> kpropertiesdialog.cpp:2795-2805
> +    std::function<QString(QCryptographicHash::Algorithm)> mapper = [this](QCryptographicHash::Algorithm alg) {
> +        const QString cache = cachedChecksum(alg);
> +        if (!cache.isEmpty()) {
> +            return cache;
> +        }
>  
> +        const QString checksum = computeChecksum(alg, properties->item().localPath());

Better get localPath before concurrent function and you should use mutex as well, simultaneously read/write is data race  i.e.

  const auto itemPath = properties->item().localPath();
  std::function<QString(QCryptographicHash::Algorithm)> mapper = [itemPath, this](QCryptographicHash::Algorithm alg) {
      QMutexLocker locker(&d->mutex);

> kpropertiesdialog.cpp:3015
>  {
> -    switch (algorithm) {
> -    case QCryptographicHash::Md5:
> -        d->m_md5 = checksum;
> -        break;
> -    case QCryptographicHash::Sha1:
> -        d->m_sha1 = checksum;
> -        break;
> -    case QCryptographicHash::Sha256:
> -        d->m_sha256 = checksum;
> -        break;
> -    default:
> -        return;
> -    }
> +    QMutexLocker locker(&d->mutex);
> +    d->cache.insert(algorithm, checksum);

Mutex is not needed here.

REPOSITORY
  R241 KIO

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

To: petermajchrak, elvisangelaccio, #vdg, colomar
Cc: colomar, anthonyfieroni, bcooksley, alexeymin, ngraham, elvisangelaccio, #frameworks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20171227/2dd4d0c2/attachment.html>


More information about the Kde-frameworks-devel mailing list