]> git.pld-linux.org Git - packages/akonadi.git/blame - 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
CommitLineData
8a8f9fb3
AM
1From 89357c7b0fc5e76091510af504058c036fa1b2f9 Mon Sep 17 00:00:00 2001
2From: Milian Wolff <mail@milianw.de>
3Date: Wed, 10 Dec 2014 21:04:24 +0100
4Subject: [PATCH 29/30] Reduce the amount of allocations by preallocating a
5 buffer.
6
7Sadly, QByteArray cannot be cleared without destroying the buffer.
8But we can guesstimate the target size of the buffer and thus
9reduce the amount of allocations.
10
11This 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
17diff --git a/libs/imapparser.cpp b/libs/imapparser.cpp
18index 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 ) {
29diff --git a/libs/tests/imapparserbenchmark.cpp b/libs/tests/imapparserbenchmark.cpp
30index 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--
602.1.0
61
This page took 0.10267 seconds and 4 git commands to generate.