From 189444d8c4a1384479962e98e699bf1fd2908de8 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 23 Feb 2023 15:00:42 +0100 Subject: [PATCH] De-pessimize QCryptographicHash::reset() in OpenSSL3 mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of going through the whole dance with provider loading, context creation etc, just call EVP_MD_CTX_reset() to reuse the already-setup context, if any. This makes QCryptographicHash::reset() adhere to its noexcept specification again (assuming EVP_MD_CTX_reset() doesn't allocate state, and, despite its non-void return type, cannot fail on a valid context), and should greatly improve the speed of reset(), addData(), resultView() cycles. Pick-to: 6.5 Change-Id: I7c35b61cbeab1ffd6dd258e8389ea614d49e2e1e Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Jan Grulich Reviewed-by: Qt CI Bot --- src/corelib/tools/qcryptographichash.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/corelib/tools/qcryptographichash.cpp b/src/corelib/tools/qcryptographichash.cpp index 8ada1277b6e..095d1910a64 100644 --- a/src/corelib/tools/qcryptographichash.cpp +++ b/src/corelib/tools/qcryptographichash.cpp @@ -547,6 +547,12 @@ void QCryptographicHashPrivate::reset() noexcept return; } + if (context && !initializationFailed) { + // everything already set up - just reset the context + EVP_MD_CTX_reset(context.get()); + return; + } + initializationFailed = true; if (method == QCryptographicHash::Md4) {