summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qcryptographichash.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2021-07-06 20:48:36 +0200
committerMarc Mutz <marc.mutz@kdab.com>2021-07-15 17:56:23 +0200
commit27d6314b9598908cbb9c2a589fb62f3653fa9062 (patch)
tree49b848a31aacec4c5540cf70af6616b7d9521cfa /src/corelib/tools/qcryptographichash.h
parentc6e092a5f84b7fc72556897b50c7697152967925 (diff)
QCryptographicHash: use a std::array to hold result (was: QByteArray)
The maximum size for a hash result is 64 atm. Even if, and esp when, we'll get to 128 and 256 bytes in the future, there's no reason to use dynamic memory, because the sizes will always be statically known. So use, essentially, a std::array<char, 64> to hold the result internally. Add a bit of convenience API on top to limit impact on the rest of the code and add a few static_asserts that ensure this is large enough. Then give users access to the internal buffer by adding QByteArrayView resultView() const noexcept. The documentation snippet is taken from QString::data(), suitably adjusted. Use resultView() in a few places instead of result(). [ChangeLog][QtCore][QCryptographicHash] Changed to use a statically-sized buffer internally. Added resultView() to access it. Change-Id: I96c35e55acacbe94529446d720c18325273ffd2f Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/tools/qcryptographichash.h')
-rw-r--r--src/corelib/tools/qcryptographichash.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/corelib/tools/qcryptographichash.h b/src/corelib/tools/qcryptographichash.h
index aecf8995d5..b3ab9c6126 100644
--- a/src/corelib/tools/qcryptographichash.h
+++ b/src/corelib/tools/qcryptographichash.h
@@ -102,7 +102,7 @@ public:
explicit QCryptographicHash(Algorithm method);
~QCryptographicHash();
- void reset();
+ void reset() noexcept;
#if QT_DEPRECATED_SINCE(6, 4)
QT_DEPRECATED_VERSION_X_6_4("Use the QByteArrayView overload instead")
@@ -115,6 +115,7 @@ public:
bool addData(QIODevice *device);
QByteArray result() const;
+ QByteArrayView resultView() const noexcept;
#ifdef QT_BUILD_FUNCTIONS_REMOVED_IN_6_3
static QByteArray hash(const QByteArray &data, Algorithm method);