summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Krause <[email protected]>2015-08-23 16:12:52 +0200
committerVolker Krause <[email protected]>2015-08-23 16:15:05 +0200
commit8d76a0335eb222c26ca7fd02713745fbf48c39be (patch)
tree69eaeea2e84628eabff80326f80181d7b6ed34b3
parent46cda1c8588a34c8d1f22f13d5933488cc947fcc (diff)
Avoid double calls to expensive/allocating functions.
There's more that can be done here: - store the MD5 result in uint64_t[2] rather than a QByteArray, even without considering malloc overhead that is not needing more space and it avoids one allocation. - run md5 on the raw data of the subject QString to avoid the UTF-8 temporary.
-rw-r--r--messagelist/storagemodel.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/messagelist/storagemodel.cpp b/messagelist/storagemodel.cpp
index 63a7ce3..cdb5639 100644
--- a/messagelist/storagemodel.cpp
+++ b/messagelist/storagemodel.cpp
@@ -263,12 +263,13 @@ bool StorageModel::initializeMessageItem(MessageList::Core::MessageItem *mi,
static QByteArray md5Encode(const QByteArray &str)
{
- if (str.trimmed().isEmpty()) {
+ auto trimmed = str.trimmed();
+ if (trimmed.isEmpty()) {
return QByteArray();
}
QCryptographicHash c(QCryptographicHash::Md5);
- c.addData(str.trimmed());
+ c.addData(trimmed);
return c.result();
}
@@ -287,16 +288,22 @@ void StorageModel::fillMessageItemThreadingData(MessageList::Core::MessageItem *
// fall through
}
case PerfectThreadingPlusReferences:
- if (!mail->references()->identifiers().isEmpty()) {
- mi->setReferencesIdMD5(md5Encode(mail->references()->identifiers().last()));
+ {
+ const auto refs = mail->references()->identifiers();
+ if (!refs.isEmpty()) {
+ mi->setReferencesIdMD5(md5Encode(refs.last()));
}
+ }
// fall through
case PerfectThreadingOnly:
+ {
mi->setMessageIdMD5(md5Encode(mail->messageID()->identifier()));
- if (!mail->inReplyTo()->identifiers().isEmpty()) {
- mi->setInReplyToIdMD5(md5Encode(mail->inReplyTo()->identifiers().first()));
+ const auto inReplyTos = mail->inReplyTo()->identifiers();
+ if (!inReplyTos.isEmpty()) {
+ mi->setInReplyToIdMD5(md5Encode(inReplyTos.first()));
}
break;
+ }
default:
Q_ASSERT(false); // should never happen
break;