mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-20 21:33:27 -07:00
Make Digest32 implicitly shared class
This commit is contained in:
parent
9553afc3c2
commit
c40408b337
2 changed files with 22 additions and 12 deletions
|
@ -85,3 +85,6 @@ namespace BitTorrent
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(BitTorrent::TorrentID)
|
Q_DECLARE_METATYPE(BitTorrent::TorrentID)
|
||||||
|
// We can declare it as Q_MOVABLE_TYPE to improve performance
|
||||||
|
// since base type uses QSharedDataPointer as the only member
|
||||||
|
Q_DECLARE_TYPEINFO(BitTorrent::TorrentID, Q_MOVABLE_TYPE);
|
||||||
|
|
|
@ -32,6 +32,8 @@
|
||||||
|
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
#include <QSharedData>
|
||||||
|
#include <QSharedDataPointer>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
template <int N>
|
template <int N>
|
||||||
|
@ -43,11 +45,11 @@ public:
|
||||||
Digest32() = default;
|
Digest32() = default;
|
||||||
|
|
||||||
Digest32(const UnderlyingType &nativeDigest)
|
Digest32(const UnderlyingType &nativeDigest)
|
||||||
: m_valid {true}
|
|
||||||
, m_nativeDigest {nativeDigest}
|
|
||||||
{
|
{
|
||||||
|
m_dataPtr->valid = true;
|
||||||
|
m_dataPtr->nativeDigest = nativeDigest;
|
||||||
const QByteArray raw = QByteArray::fromRawData(nativeDigest.data(), length());
|
const QByteArray raw = QByteArray::fromRawData(nativeDigest.data(), length());
|
||||||
m_hashString = QString::fromLatin1(raw.toHex());
|
m_dataPtr->hashString = QString::fromLatin1(raw.toHex());
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr int length()
|
static constexpr int length()
|
||||||
|
@ -57,12 +59,12 @@ public:
|
||||||
|
|
||||||
bool isValid() const
|
bool isValid() const
|
||||||
{
|
{
|
||||||
return m_valid;
|
return m_dataPtr->valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
operator UnderlyingType() const
|
operator UnderlyingType() const
|
||||||
{
|
{
|
||||||
return m_nativeDigest;
|
return m_dataPtr->nativeDigest;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Digest32 fromString(const QString &digestString)
|
static Digest32 fromString(const QString &digestString)
|
||||||
|
@ -75,22 +77,27 @@ public:
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
Digest32 result;
|
Digest32 result;
|
||||||
result.m_valid = true;
|
result.m_dataPtr->valid = true;
|
||||||
result.m_hashString = digestString;
|
result.m_dataPtr->hashString = digestString;
|
||||||
result.m_nativeDigest.assign(raw.constData());
|
result.m_dataPtr->nativeDigest.assign(raw.constData());
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString toString() const
|
QString toString() const
|
||||||
{
|
{
|
||||||
return m_hashString;
|
return m_dataPtr->hashString;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_valid = false;
|
struct Data : public QSharedData
|
||||||
UnderlyingType m_nativeDigest;
|
{
|
||||||
QString m_hashString;
|
bool valid = false;
|
||||||
|
UnderlyingType nativeDigest;
|
||||||
|
QString hashString;
|
||||||
|
};
|
||||||
|
|
||||||
|
QSharedDataPointer<Data> m_dataPtr {new Data};
|
||||||
};
|
};
|
||||||
|
|
||||||
template <int N>
|
template <int N>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue