Commit 6fdb77fa authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Minor optimization

parent 6456bf00
......@@ -29,18 +29,28 @@ DKIMUtilTest::DKIMUtilTest(QObject *parent)
void DKIMUtilTest::shouldTestBodyCanonizationRelaxed()
{
{
QString ba = QStringLiteral("-- \nLaurent Montel | laurent.montel@kdab.com | KDE/Qt Senior Software Engineer \nKDAB (France) S.A.S., a KDAB Group company\nTel: France +33 (0)4 90 84 08 53, http://www.kdab.fr\nKDAB - The Qt, C++ and OpenGL Experts\n\n\n");
QString result = MessageViewer::DKIMUtil::bodyCanonizationRelaxed(ba);
QBENCHMARK {
{
QString ba = QStringLiteral("-- \nLaurent Montel | laurent.montel@kdab.com | KDE/Qt Senior Software Engineer \nKDAB (France) S.A.S., a KDAB Group company\nTel: France +33 (0)4 90 84 08 53, http://www.kdab.fr\nKDAB - The Qt, C++ and OpenGL Experts\n\n\n");
QString result = MessageViewer::DKIMUtil::bodyCanonizationRelaxed(ba);
QCOMPARE(MessageViewer::DKIMUtil::generateHash(result.toUtf8(), QCryptographicHash::Sha256), "jnEyWN7LwPIBgES0mElYDek3lmyrRtSwUjDR2Ge08Xw=");
}
{
QString ba = QStringLiteral("Bla bla\n\nbli\t\tblo\nTest\n\n\n\n\n");
QString result = MessageViewer::DKIMUtil::bodyCanonizationRelaxed(ba);
QCOMPARE(MessageViewer::DKIMUtil::generateHash(result.toUtf8(), QCryptographicHash::Sha256), "jnEyWN7LwPIBgES0mElYDek3lmyrRtSwUjDR2Ge08Xw=");
}
{
QString ba = QStringLiteral("Bla bla\n\nbli\t\tblo\nTest\n\n\n\n\n");
QString result = MessageViewer::DKIMUtil::bodyCanonizationRelaxed(ba);
QCOMPARE(MessageViewer::DKIMUtil::generateHash(result.toUtf8(), QCryptographicHash::Sha256), "DrwZwEC82qsIhJtHlq76T00vAUcrSrHbJh8wY5GTAws=");
QCOMPARE(MessageViewer::DKIMUtil::generateHash(result.toUtf8(), QCryptographicHash::Sha256), "DrwZwEC82qsIhJtHlq76T00vAUcrSrHbJh8wY5GTAws=");
}
}
// BEFORE
// RESULT : DKIMUtilTest::shouldTestBodyCanonizationRelaxed():
// 0.087 msecs per iteration (total: 90, iterations: 1024)
// AFTER
// RESULT : DKIMUtilTest::shouldTestBodyCanonizationRelaxed():
// 0.014 msecs per iteration (total: 59, iterations: 4096)
}
void DKIMUtilTest::shouldVerifyEmailDomain()
......
......@@ -45,9 +45,12 @@ QString MessageViewer::DKIMUtil::bodyCanonizationRelaxed(QString body)
*/
body.replace(QStringLiteral("\n"), QStringLiteral("\r\n"));
body.replace(QRegularExpression(QStringLiteral("[ \t]+\r\n")), QStringLiteral("\r\n"));
body.replace(QRegularExpression(QStringLiteral("[ \t]+")), QStringLiteral(" "));
body.replace(QRegularExpression(QStringLiteral("((\r\n)+?)$")), QStringLiteral("\r\n"));
static const QRegularExpression reg1(QStringLiteral("[ \t]+\r\n"));
body.replace(reg1, QStringLiteral("\r\n"));
static const QRegularExpression reg2(QStringLiteral("[ \t]+"));
body.replace(reg2, QStringLiteral(" "));
static const QRegularExpression reg3(QStringLiteral("((\r\n)+?)$"));
body.replace(QRegularExpression(reg3), QStringLiteral("\r\n"));
if (body == QLatin1String("\r\n")) {
body.clear();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment