aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Vrátil <[email protected]>2015-08-21 15:41:04 +0200
committerDan Vrátil <[email protected]>2015-08-21 15:41:14 +0200
commit294e2a5e7fdfd9c1090d38b6bd1e0740cc97b281 (patch)
treefc1efeac5e20dfe7ecb272cc4e456d52b0293f34
parentcfad4c5e50a180ac16b558554cca2531eb1e16ea (diff)
Reduce temporary allocations when parsing headers
REVIEW: 124865
-rw-r--r--src/kmime_header_parsing.cpp10
-rw-r--r--src/kmime_util.cpp4
2 files changed, 9 insertions, 5 deletions
diff --git a/src/kmime_header_parsing.cpp b/src/kmime_header_parsing.cpp
index 2bcdc5a..3929a58 100644
--- a/src/kmime_header_parsing.cpp
+++ b/src/kmime_header_parsing.cpp
@@ -2214,14 +2214,18 @@ Headers::Base *extractFirstHeader(QByteArray &head)
const int endOfFieldHeader = startOfFieldBody;
if (startOfFieldBody > -1) { //there is another header
+ // Split the original data
+ head[startOfFieldBody] = '\0';
+ // rawType references the actual data from 'head'
+ QByteArray rawType = QByteArray::fromRawData(head.constData(), startOfFieldBody);
+
startOfFieldBody++; //skip the ':'
if (head[startOfFieldBody] == ' ') { // skip the space after the ':', if there
startOfFieldBody++;
}
endOfFieldBody = findHeaderLineEnd(head, startOfFieldBody, &folded);
-
- QByteArray rawType = head.left(endOfFieldHeader);
- QByteArray rawFieldBody = head.mid(startOfFieldBody, endOfFieldBody - startOfFieldBody);
+ // rawFieldBody references actual data from 'heaed'
+ QByteArray rawFieldBody = QByteArray::fromRawData(head.constData() + startOfFieldBody, endOfFieldBody - startOfFieldBody);
if (folded) {
rawFieldBody = unfoldHeader(rawFieldBody);
}
diff --git a/src/kmime_util.cpp b/src/kmime_util.cpp
index 39c4915..56ac57b 100644
--- a/src/kmime_util.cpp
+++ b/src/kmime_util.cpp
@@ -583,7 +583,7 @@ QByteArray unfoldHeader(const QByteArray &header)
}
}
- result += header.mid(pos, foldBegin - pos);
+ result.append(header.constData() + pos, foldBegin - pos);
if (foldEnd < header.length() - 1) {
result += ' ';
}
@@ -591,7 +591,7 @@ QByteArray unfoldHeader(const QByteArray &header)
}
const int len = header.length();
if (len > pos) {
- result += header.mid(pos, len - pos);
+ result.append(header.constData() + pos, len - pos);
}
return result;
}