1 From c733429f4fa9696fb027ddc946e54f6bbb68deaf Mon Sep 17 00:00:00 2001
2 From: Milian Wolff <mail@milianw.de>
3 Date: Wed, 10 Dec 2014 21:16:45 +0100
4 Subject: [PATCH 30/30] Preallocate a capacity of 16 for the returned list.
6 See also 159abaf2f372eaa633db8f69ff6b1edd459998cc in kdepimlibs on
7 why. I'll quote it here again:
9 In my data, most often the final size of fetchResponse is 16.
10 By reserving that data upfront, we can get rid of 3/4 of the
11 list allocations, according to the growth-strategy outlined here:
12 http://qt-project.org/doc/qt-4.8/containers.html#growth-strategies
13 I.e. before, we'd allocate 4, 8, 12, 16. Now we directly allocate
16 Thing is, doing this outside of akonadi has no effect, as QList::clear
17 destroys the internal buffer. With the added benchmark, I now verified
18 that this patch here does have a positive effect.
20 libs/imapparser.cpp | 2 ++
21 libs/tests/imapparserbenchmark.cpp | 52 ++++++++++++++++++++++++++------------
22 2 files changed, 38 insertions(+), 16 deletions(-)
24 diff --git a/libs/imapparser.cpp b/libs/imapparser.cpp
25 index f3301e7..f5a7457 100644
26 --- a/libs/imapparser.cpp
27 +++ b/libs/imapparser.cpp
28 @@ -79,6 +79,8 @@ int parseParenthesizedListHelper( const QByteArray &data, T &result, int start )
35 int sublistBegin = start;
36 bool insideQuote = false;
37 diff --git a/libs/tests/imapparserbenchmark.cpp b/libs/tests/imapparserbenchmark.cpp
38 index ee861a0..7545238 100644
39 --- a/libs/tests/imapparserbenchmark.cpp
40 +++ b/libs/tests/imapparserbenchmark.cpp
41 @@ -27,6 +27,25 @@ Q_DECLARE_METATYPE( QList<QByteArray> )
42 class ImapParserBenchmark : public QObject
46 + void geneateParseParenthesizedListData()
48 + QTest::addColumn<QByteArray>( "data" );
49 + QTest::newRow( "empty" ) << QByteArray();
50 + QTest::newRow( "unnested" ) << QByteArray("(\"Foo Bar\" NIL \"foobar\" \"test.com\")");
51 + QTest::newRow( "nested" ) << QByteArray("((\"Foo Bar\" NIL \"foobar\" \"test.com\"))");
52 + QTest::newRow( "nested-long" ) << QByteArray("(UID 86 REV 0 MIMETYPE \"message/rfc822\" COLLECTIONID 13 SIZE 6114 FLAGS (\\SEEN)"
53 + " ANCESTORS ((13 \"/INBOX\") (12 \"imap://mail@mail.test.com/\") (0 \"\")) PLD:ENVELOPE[1] {396}"
54 + " (\"Fri, 04 Jun 2010 09:07:54 +0200\" \"Re: [ADMIN] foobar available again!\""
55 + " ((\"Foo Bar\" NIL \"foobar\" \"test.com\"))"
57 + " ((\"Asdf Bla Blub\" NIL \"asdf.bla.blub\" \"123test.org\"))"
58 + " ((NIL NIL \"muh.kuh\" \"lalala.com\") (\"Konqi KDE\" NIL \"konqi\" \"kde.org\") (NIL NIL \"all\" \"test.com\"))"
59 + " NIL \"<201006040905.33367.foo.bar@test.com>\" \"<4C08A64A.9020205@123test.org>\""
60 + " \"<201006040142.56540.muh.kuh@lalala.com> <201006040704.39648.konqi@kde.org> <201006040905.33367.foo.bar@test.com>\""
67 @@ -68,25 +87,12 @@ class ImapParserBenchmark : public QObject
71 - void parseParenthesizedList_data()
72 + void parseParenthesizedQVarLengthArray_data()
74 - QTest::addColumn<QByteArray>( "data" );
75 - QTest::newRow( "empty" ) << QByteArray();
76 - QTest::newRow( "unnested" ) << QByteArray("(\"Foo Bar\" NIL \"foobar\" \"test.com\")");
77 - QTest::newRow( "nested" ) << QByteArray("((\"Foo Bar\" NIL \"foobar\" \"test.com\"))");
78 - QTest::newRow( "nested-long" ) << QByteArray("(UID 86 REV 0 MIMETYPE \"message/rfc822\" COLLECTIONID 13 SIZE 6114 FLAGS (\\SEEN)"
79 - " ANCESTORS ((13 \"/INBOX\") (12 \"imap://mail@mail.test.com/\") (0 \"\")) PLD:ENVELOPE[1] {396}"
80 - " (\"Fri, 04 Jun 2010 09:07:54 +0200\" \"Re: [ADMIN] foobar available again!\""
81 - " ((\"Foo Bar\" NIL \"foobar\" \"test.com\"))"
83 - " ((\"Asdf Bla Blub\" NIL \"asdf.bla.blub\" \"123test.org\"))"
84 - " ((NIL NIL \"muh.kuh\" \"lalala.com\") (\"Konqi KDE\" NIL \"konqi\" \"kde.org\") (NIL NIL \"all\" \"test.com\"))"
85 - " NIL \"<201006040905.33367.foo.bar@test.com>\" \"<4C08A64A.9020205@123test.org>\""
86 - " \"<201006040142.56540.muh.kuh@lalala.com> <201006040704.39648.konqi@kde.org> <201006040905.33367.foo.bar@test.com>\""
88 + geneateParseParenthesizedListData();
91 - void parseParenthesizedList()
92 + void parseParenthesizedQVarLengthArray()
94 QFETCH( QByteArray, data );
95 QVarLengthArray<QByteArray, 16> result;
96 @@ -95,6 +101,20 @@ class ImapParserBenchmark : public QObject
100 + void parseParenthesizedQList_data()
102 + geneateParseParenthesizedListData();
105 + void parseParenthesizedQList()
107 + QFETCH( QByteArray, data );
108 + QList<QByteArray> result;
110 + ImapParser::parseParenthesizedList( data, result, 0 );
114 void parseString_data()
116 QTest::addColumn<QByteArray>( "data" );