From 9a289b7271044e936b924df209a255046f57d3f6 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 21 Feb 2023 09:15:45 +0100 Subject: [PATCH] QMessageAuthenticationCode: apply the QCryptographicHash::hash() optimization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... 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 Change-Id: I4d144fcfadc0b8c9ba78d395ff7279b2d5d7b050 Reviewed-by: Fabian Kosmale Reviewed-by: MÃ¥rten Nordheim (cherry picked from commit d32d2137b7d513f38450d3a5e07a997c3bc90aa1) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/tools/qmessageauthenticationcode.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/corelib/tools/qmessageauthenticationcode.cpp b/src/corelib/tools/qmessageauthenticationcode.cpp index 5853e9951ec..4b8017953bf 100644 --- a/src/corelib/tools/qmessageauthenticationcode.cpp +++ b/src/corelib/tools/qmessageauthenticationcode.cpp @@ -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