From ad6e2b4b9439744b4939cf2b449e0c5fd2253e6c Mon Sep 17 00:00:00 2001 From: Prince Gupta Date: Sun, 6 Mar 2022 18:43:43 +0530 Subject: [PATCH] Create hash string of Digest on demand most of the time hash string is not needed and InfoHash is often used as temporaries for torrent searching in handling of torrent alerts. This improves the creation time of Infohash --- src/base/digest32.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/base/digest32.h b/src/base/digest32.h index f24b448f3..bf007f9d3 100644 --- a/src/base/digest32.h +++ b/src/base/digest32.h @@ -50,8 +50,7 @@ public: { m_dataPtr->valid = true; m_dataPtr->nativeDigest = nativeDigest; - const QByteArray raw = QByteArray::fromRawData(nativeDigest.data(), length()); - m_dataPtr->hashString = QString::fromLatin1(raw.toHex()); + m_dataPtr->hashString.clear(); // hashString is created on demand } static constexpr int length() @@ -91,6 +90,12 @@ public: QString toString() const { + if (m_dataPtr->hashString.isEmpty()) + { + const QByteArray raw = QByteArray::fromRawData(m_dataPtr->nativeDigest.data(), length()); + const_cast(this)->m_dataPtr->hashString = QString::fromLatin1(raw.toHex()); + } + return m_dataPtr->hashString; }