Blob Blame History Raw
From da5751c7b1589d2ea5800a3cf96dfc93b23b9783 Mon Sep 17 00:00:00 2001
From: Milian Wolff <mail@milianw.de>
Date: Tue, 9 Dec 2014 14:35:04 +0100
Subject: [PATCH 28/30] Extend imapparser benchmark and keep static data
 around.

This gets rid of some temporary allocations and thus speeds up
the whole process a bit.

REVIEW: 121406
---
 libs/imapparser.cpp                |  5 +++--
 libs/tests/imapparserbenchmark.cpp | 22 ++++++++++++++++++++++
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/libs/imapparser.cpp b/libs/imapparser.cpp
index 9b437e2..6f9f592 100644
--- a/libs/imapparser.cpp
+++ b/libs/imapparser.cpp
@@ -364,7 +364,8 @@ int ImapParser::parseNumber( const QByteArray &data, qint64 &result, bool *ok, i
 QByteArray ImapParser::quote( const QByteArray &data )
 {
   if ( data.isEmpty() ) {
-    return QByteArray( "\"\"" );
+    static const QByteArray empty( "\"\"" );
+    return empty;
   }
 
   const int inputLength = data.length();
@@ -499,7 +500,7 @@ int ImapParser::parseDateTime( const QByteArray &data, QDateTime &dateTime, int
   }
 
   pos += 3;
-  const QByteArray shortMonthNames( "janfebmaraprmayjunjulaugsepoctnovdec" );
+  static const QByteArray shortMonthNames( "janfebmaraprmayjunjulaugsepoctnovdec" );
   int month = shortMonthNames.indexOf( data.mid( pos, 3 ).toLower() );
   if ( month == -1 ) {
     return start;
diff --git a/libs/tests/imapparserbenchmark.cpp b/libs/tests/imapparserbenchmark.cpp
index 17dac66..fd4335c 100644
--- a/libs/tests/imapparserbenchmark.cpp
+++ b/libs/tests/imapparserbenchmark.cpp
@@ -94,6 +94,28 @@ class ImapParserBenchmark : public QObject
         ImapParser::parseParenthesizedList( data, result, 0 );
       }
     }
+
+    void parseNumber()
+    {
+      QByteArray data( "123456" );
+      qint64 result;
+      bool ok = false;
+      QBENCHMARK {
+        ImapParser::parseNumber( data, result, &ok );
+      }
+      QVERIFY(ok);
+      QCOMPARE(result, qint64(123456));
+    }
+
+    void parseDateTime()
+    {
+      QByteArray data( "28-May-2006 01:03:35 +0000" );
+      QDateTime result;
+      QBENCHMARK {
+        ImapParser::parseDateTime( data, result );
+      }
+      QCOMPARE(result.toString( QString::fromUtf8( "dd-MMM-yyyy hh:mm:ss +0000" ) ), QString::fromUtf8( data ));
+    }
 };
 
 #include "imapparserbenchmark.moc"
-- 
2.1.0