Commit a5940492 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Use some static QRegularExpression

parent dfbd6e36
......@@ -43,15 +43,66 @@ void DKIMAuthenticationStatusInfoTest::shouldParseKey()
QFETCH(MessageViewer::DKIMAuthenticationStatusInfo, result);
QFETCH(bool, relaxingParsing);
QFETCH(bool, success);
MessageViewer::DKIMAuthenticationStatusInfo info;
const bool val = info.parseAuthenticationStatus(key, relaxingParsing);
QCOMPARE(val, success);
const bool compareResult = result == info;
if (!compareResult) {
qDebug() << "parse info: " << info;
qDebug() << "expected: " << result;
QBENCHMARK {
MessageViewer::DKIMAuthenticationStatusInfo info;
const bool val = info.parseAuthenticationStatus(key, relaxingParsing);
QCOMPARE(val, success);
const bool compareResult = result == info;
if (!compareResult) {
qDebug() << "parse info: " << info;
qDebug() << "expected: " << result;
}
QVERIFY(compareResult);
}
QVERIFY(compareResult);
// Before
// PASS : DKIMAuthenticationStatusInfoTest::initTestCase()
// PASS : DKIMAuthenticationStatusInfoTest::shouldHaveDefaultValue()
// PASS : DKIMAuthenticationStatusInfoTest::shouldParseKey(empty)
// RESULT : DKIMAuthenticationStatusInfoTest::shouldParseKey():"empty":
// 0.81 msecs per iteration (total: 52, iterations: 64)
// PASS : DKIMAuthenticationStatusInfoTest::shouldParseKey(test1)
// RESULT : DKIMAuthenticationStatusInfoTest::shouldParseKey():"test1":
// 18 msecs per iteration (total: 72, iterations: 4)
// PASS : DKIMAuthenticationStatusInfoTest::shouldParseKey(none)
// RESULT : DKIMAuthenticationStatusInfoTest::shouldParseKey():"none":
// 2.0 msecs per iteration (total: 65, iterations: 32)
// PASS : DKIMAuthenticationStatusInfoTest::shouldParseKey(none2)
// RESULT : DKIMAuthenticationStatusInfoTest::shouldParseKey():"none2":
// 2.0 msecs per iteration (total: 66, iterations: 32)
// PASS : DKIMAuthenticationStatusInfoTest::shouldParseKey(reason)
// RESULT : DKIMAuthenticationStatusInfoTest::shouldParseKey():"reason":
// 13 msecs per iteration (total: 52, iterations: 4)
// PASS : DKIMAuthenticationStatusInfoTest::shouldParseKey(reason2)
// RESULT : DKIMAuthenticationStatusInfoTest::shouldParseKey():"reason2":
// 12 msecs per iteration (total: 97, iterations: 8)
// PASS : DKIMAuthenticationStatusInfoTest::shouldParseKey(gmails)
// RESULT : DKIMAuthenticationStatusInfoTest::shouldParseKey():"gmails":
// 7.0 msecs per iteration (total: 56, iterations: 8)
// PASS : DKIMAuthenticationStatusInfoTest::cleanupTestCase()
// AFTER
//RESULT : DKIMAuthenticationStatusInfoTest::shouldParseKey():"empty":
// 0.0089 msecs per iteration (total: 73, iterations: 8192)
//PASS : DKIMAuthenticationStatusInfoTest::shouldParseKey(test1)
//RESULT : DKIMAuthenticationStatusInfoTest::shouldParseKey():"test1":
// 0.23 msecs per iteration (total: 59, iterations: 256)
//PASS : DKIMAuthenticationStatusInfoTest::shouldParseKey(none)
//RESULT : DKIMAuthenticationStatusInfoTest::shouldParseKey():"none":
// 0.023 msecs per iteration (total: 96, iterations: 4096)
//PASS : DKIMAuthenticationStatusInfoTest::shouldParseKey(none2)
//RESULT : DKIMAuthenticationStatusInfoTest::shouldParseKey():"none2":
// 0.023 msecs per iteration (total: 96, iterations: 4096)
//PASS : DKIMAuthenticationStatusInfoTest::shouldParseKey(reason)
//RESULT : DKIMAuthenticationStatusInfoTest::shouldParseKey():"reason":
// 0.16 msecs per iteration (total: 83, iterations: 512)
//PASS : DKIMAuthenticationStatusInfoTest::shouldParseKey(reason2)
//RESULT : DKIMAuthenticationStatusInfoTest::shouldParseKey():"reason2":
// 0.14 msecs per iteration (total: 75, iterations: 512)
//PASS : DKIMAuthenticationStatusInfoTest::shouldParseKey(gmails)
//RESULT : DKIMAuthenticationStatusInfoTest::shouldParseKey():"gmails":
// 0.085 msecs per iteration (total: 88, iterations: 1024)
//PASS : DKIMAuthenticationStatusInfoTest::cleanupTestCase()
}
void DKIMAuthenticationStatusInfoTest::shouldParseKey_data()
......
......@@ -44,7 +44,8 @@ bool DKIMAuthenticationStatusInfo::parseAuthenticationStatus(const QString &key,
QRegularExpressionMatch match;
const QString regStr = DKIMAuthenticationStatusInfoUtil::value_cp() + QLatin1String("(?:") + DKIMAuthenticationStatusInfoUtil::cfws_p() + QLatin1String("([0-9]+)") + DKIMAuthenticationStatusInfoUtil::cfws_op() + QLatin1String(" )?");
//qDebug() << " regStr" << regStr;
int index = valueKey.indexOf(QRegularExpression(regStr), 0, &match);
static const QRegularExpression regular1(regStr);
int index = valueKey.indexOf(regular1, 0, &match);
if (index != -1) {
mAuthservId = match.captured(1);
const QString authVersionStr = match.captured(2);
......@@ -62,7 +63,8 @@ bool DKIMAuthenticationStatusInfo::parseAuthenticationStatus(const QString &key,
// check if message authentication was performed
const QString authResultStr = DKIMAuthenticationStatusInfoUtil::regexMatchO(DKIMAuthenticationStatusInfoUtil::value_cp() + QLatin1String(";") + DKIMAuthenticationStatusInfoUtil::cfws_op() + QLatin1String("?none"));
//qDebug() << "authResultStr "<<authResultStr;
index = valueKey.indexOf(QRegularExpression(authResultStr), 0, &match);
static const QRegularExpression regular2(authResultStr);
index = valueKey.indexOf(regular2, 0, &match);
if (index != -1) {
//no result
return false;
......@@ -91,7 +93,8 @@ DKIMAuthenticationStatusInfo::AuthStatusInfo DKIMAuthenticationStatusInfo::parse
//qDebug() << "methodspec_p " << methodspec_p;
QRegularExpressionMatch match;
int index = valueKey.indexOf(QRegularExpression(methodspec_p), 0, &match);
static const QRegularExpression reg2(methodspec_p);
int index = valueKey.indexOf(reg2, 0, &match);
if (index == -1) {
valueKey = QString(); //remove it !
qCDebug(MESSAGEVIEWER_DKIMCHECKER_LOG) << "methodspec not found ";
......@@ -112,7 +115,8 @@ DKIMAuthenticationStatusInfo::AuthStatusInfo DKIMAuthenticationStatusInfo::parse
// 3) extract reasonspec (optional)
const QString reasonspec_p = DKIMAuthenticationStatusInfoUtil::regexMatchO(QLatin1String("reason") + DKIMAuthenticationStatusInfoUtil::cfws_op() + QLatin1Char('=') + DKIMAuthenticationStatusInfoUtil::cfws_op() + DKIMAuthenticationStatusInfoUtil::value_cp());
index = valueKey.indexOf(QRegularExpression(reasonspec_p), 0, &match);
static const QRegularExpression reg31(reasonspec_p);
index = valueKey.indexOf(reg31, 0, &match);
if (index != -1) {
//qDebug() << " reason " << match.capturedTexts();
authStatusInfo.reason = match.captured(2);
......@@ -134,7 +138,7 @@ DKIMAuthenticationStatusInfo::AuthStatusInfo DKIMAuthenticationStatusInfo::parse
//qDebug() << "propspec_p " << propspec_p;
const QString regexp = DKIMAuthenticationStatusInfoUtil::regexMatchO(propspec_p);
const QRegularExpression reg(regexp);
static const QRegularExpression reg(regexp);
if (!reg.isValid()) {
qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) << " reg error : " << reg.errorString();
} else {
......
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