]> git.pld-linux.org Git - packages/akonadi.git/blob - 0029-Reduce-the-amount-of-allocations-by-preallocating-a-.patch
boost rebuild
[packages/akonadi.git] / 0029-Reduce-the-amount-of-allocations-by-preallocating-a-.patch
1 From 89357c7b0fc5e76091510af504058c036fa1b2f9 Mon Sep 17 00:00:00 2001
2 From: Milian Wolff <mail@milianw.de>
3 Date: Wed, 10 Dec 2014 21:04:24 +0100
4 Subject: [PATCH 29/30] Reduce the amount of allocations by preallocating a
5  buffer.
6
7 Sadly, QByteArray cannot be cleared without destroying the buffer.
8 But we can guesstimate the target size of the buffer and thus
9 reduce the amount of allocations.
10
11 This also adds a benchmark for ImapParser::parseString.
12 ---
13  libs/imapparser.cpp                |  1 +
14  libs/tests/imapparserbenchmark.cpp | 19 +++++++++++++++++++
15  2 files changed, 20 insertions(+)
16
17 diff --git a/libs/imapparser.cpp b/libs/imapparser.cpp
18 index 6f9f592..f3301e7 100644
19 --- a/libs/imapparser.cpp
20 +++ b/libs/imapparser.cpp
21 @@ -186,6 +186,7 @@ int ImapParser::parseQuotedString( const QByteArray &data, QByteArray &result, i
22    // quoted string
23    if ( data[begin] == '"' ) {
24      ++begin;
25 +    result.reserve(qMin(32, data.size() - begin));
26      for ( int i = begin; i < data.length(); ++i ) {
27        const char ch = data.at( i );
28        if ( foundSlash ) {
29 diff --git a/libs/tests/imapparserbenchmark.cpp b/libs/tests/imapparserbenchmark.cpp
30 index fd4335c..ee861a0 100644
31 --- a/libs/tests/imapparserbenchmark.cpp
32 +++ b/libs/tests/imapparserbenchmark.cpp
33 @@ -95,6 +95,25 @@ class ImapParserBenchmark : public QObject
34        }
35      }
36  
37 +    void parseString_data()
38 +    {
39 +      QTest::addColumn<QByteArray>( "data" );
40 +      QTest::newRow("plain") << QByteArray("fooobarasdf something more lalala");
41 +      QTest::newRow("quoted") << QByteArray("\"fooobarasdf\" something more lalala");
42 +    }
43 +
44 +    void parseString()
45 +    {
46 +      QFETCH(QByteArray, data);
47 +      QByteArray result;
48 +      qint64 sum = 0;
49 +      QBENCHMARK {
50 +        sum += ImapParser::parseString( data, result );
51 +      }
52 +      QVERIFY(!result.isEmpty());
53 +      QVERIFY(sum > 0);
54 +    }
55 +
56      void parseNumber()
57      {
58        QByteArray data( "123456" );
59 -- 
60 2.1.0
61
This page took 0.096124 seconds and 3 git commands to generate.