1 From da5751c7b1589d2ea5800a3cf96dfc93b23b9783 Mon Sep 17 00:00:00 2001
2 From: Milian Wolff <mail@milianw.de>
3 Date: Tue, 9 Dec 2014 14:35:04 +0100
4 Subject: [PATCH 28/30] Extend imapparser benchmark and keep static data
7 This gets rid of some temporary allocations and thus speeds up
8 the whole process a bit.
12 libs/imapparser.cpp | 5 +++--
13 libs/tests/imapparserbenchmark.cpp | 22 ++++++++++++++++++++++
14 2 files changed, 25 insertions(+), 2 deletions(-)
16 diff --git a/libs/imapparser.cpp b/libs/imapparser.cpp
17 index 9b437e2..6f9f592 100644
18 --- a/libs/imapparser.cpp
19 +++ b/libs/imapparser.cpp
20 @@ -364,7 +364,8 @@ int ImapParser::parseNumber( const QByteArray &data, qint64 &result, bool *ok, i
21 QByteArray ImapParser::quote( const QByteArray &data )
23 if ( data.isEmpty() ) {
24 - return QByteArray( "\"\"" );
25 + static const QByteArray empty( "\"\"" );
29 const int inputLength = data.length();
30 @@ -499,7 +500,7 @@ int ImapParser::parseDateTime( const QByteArray &data, QDateTime &dateTime, int
34 - const QByteArray shortMonthNames( "janfebmaraprmayjunjulaugsepoctnovdec" );
35 + static const QByteArray shortMonthNames( "janfebmaraprmayjunjulaugsepoctnovdec" );
36 int month = shortMonthNames.indexOf( data.mid( pos, 3 ).toLower() );
39 diff --git a/libs/tests/imapparserbenchmark.cpp b/libs/tests/imapparserbenchmark.cpp
40 index 17dac66..fd4335c 100644
41 --- a/libs/tests/imapparserbenchmark.cpp
42 +++ b/libs/tests/imapparserbenchmark.cpp
43 @@ -94,6 +94,28 @@ class ImapParserBenchmark : public QObject
44 ImapParser::parseParenthesizedList( data, result, 0 );
50 + QByteArray data( "123456" );
54 + ImapParser::parseNumber( data, result, &ok );
57 + QCOMPARE(result, qint64(123456));
60 + void parseDateTime()
62 + QByteArray data( "28-May-2006 01:03:35 +0000" );
65 + ImapParser::parseDateTime( data, result );
67 + QCOMPARE(result.toString( QString::fromUtf8( "dd-MMM-yyyy hh:mm:ss +0000" ) ), QString::fromUtf8( data ));
71 #include "imapparserbenchmark.moc"