]> git.pld-linux.org Git - packages/akonadi.git/blob - 0030-Preallocate-a-capacity-of-16-for-the-returned-list.patch
boost rebuild
[packages/akonadi.git] / 0030-Preallocate-a-capacity-of-16-for-the-returned-list.patch
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.
5
6 See also 159abaf2f372eaa633db8f69ff6b1edd459998cc in kdepimlibs on
7 why. I'll quote it here again:
8
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
14     room for 16.
15
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.
19 ---
20  libs/imapparser.cpp                |  2 ++
21  libs/tests/imapparserbenchmark.cpp | 52 ++++++++++++++++++++++++++------------
22  2 files changed, 38 insertions(+), 16 deletions(-)
23
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 )
29      return start;
30    }
31  
32 +  result.reserve(16);
33 +
34    int count = 0;
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
43  {
44    Q_OBJECT
45 +  private:
46 +    void geneateParseParenthesizedListData()
47 +    {
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\"))"
56 +                                                   " NIL NIL"
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>\""
61 +                                                   "))");
62 +    }
63 +
64    private Q_SLOTS:
65      void quote_data()
66      {
67 @@ -68,25 +87,12 @@ class ImapParserBenchmark : public QObject
68        }
69      }
70  
71 -    void parseParenthesizedList_data()
72 +    void parseParenthesizedQVarLengthArray_data()
73      {
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\"))"
82 -                                                   " NIL NIL"
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>\""
87 -                                                   "))");
88 +      geneateParseParenthesizedListData();
89      }
90  
91 -    void parseParenthesizedList()
92 +    void parseParenthesizedQVarLengthArray()
93      {
94        QFETCH( QByteArray, data );
95        QVarLengthArray<QByteArray, 16> result;
96 @@ -95,6 +101,20 @@ class ImapParserBenchmark : public QObject
97        }
98      }
99  
100 +    void parseParenthesizedQList_data()
101 +    {
102 +      geneateParseParenthesizedListData();
103 +    }
104 +
105 +    void parseParenthesizedQList()
106 +    {
107 +      QFETCH( QByteArray, data );
108 +      QList<QByteArray> result;
109 +      QBENCHMARK {
110 +        ImapParser::parseParenthesizedList( data, result, 0 );
111 +      }
112 +    }
113 +
114      void parseString_data()
115      {
116        QTest::addColumn<QByteArray>( "data" );
117 -- 
118 2.1.0
119
This page took 0.121722 seconds and 3 git commands to generate.