QMessageAuthenticationCode: apply the QCryptographicHash::hash() optimization

... of creating a Private instead of the public class on the stack.

This avoids its memory-allocation, as well as the overhead of the mutex
in finalize().

Task-number: QTBUG-111347
Pick-to: 6.5
Change-Id: I4d144fcfadc0b8c9ba78d395ff7279b2d5d7b050
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
bb10
Marc Mutz 2023-02-21 09:15:45 +01:00
parent 2449af142f
commit d32d2137b7
1 changed files with 6 additions and 4 deletions

View File

@ -257,10 +257,12 @@ void QMessageAuthenticationCodePrivate::finalizeUnchecked()
QByteArray QMessageAuthenticationCode::hash(const QByteArray &message, const QByteArray &key,
QCryptographicHash::Algorithm method)
{
QMessageAuthenticationCode mac(method);
mac.setKey(key);
mac.addData(message);
return mac.result();
QMessageAuthenticationCodePrivate mac(method);
mac.key = key;
mac.initMessageHash();
mac.messageHash.addData(message);
mac.finalizeUnchecked();
return mac.result;
}
QT_END_NAMESPACE