summaryrefslogtreecommitdiffstats
path: root/common/propertymapper.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-05-12 14:26:07 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-05-12 14:26:07 +0200
commit85a4d5ac9561b639c47721e4e2305b6ced6be261 (patch)
treebf75b2e6938121c0165bdc14081582fbc33de0de /common/propertymapper.cpp
parentb9af56291f5bfc898ce232b4ebf5065554484962 (diff)
downloadsink-85a4d5ac9561b639c47721e4e2305b6ced6be261.tar.gz
sink-85a4d5ac9561b639c47721e4e2305b6ced6be261.zip
QDateTime::toString is really slow
Diffstat (limited to 'common/propertymapper.cpp')
-rw-r--r--common/propertymapper.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/common/propertymapper.cpp b/common/propertymapper.cpp
index c72cf31..c14a62e 100644
--- a/common/propertymapper.cpp
+++ b/common/propertymapper.cpp
@@ -21,6 +21,7 @@
21 21
22#include "applicationdomaintype.h" 22#include "applicationdomaintype.h"
23#include <QDateTime> 23#include <QDateTime>
24#include <QDataStream>
24#include "mail_generated.h" 25#include "mail_generated.h"
25#include "contact_generated.h" 26#include "contact_generated.h"
26 27
@@ -66,7 +67,10 @@ template <>
66flatbuffers::uoffset_t variantToProperty<QDateTime>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) 67flatbuffers::uoffset_t variantToProperty<QDateTime>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb)
67{ 68{
68 if (property.isValid()) { 69 if (property.isValid()) {
69 return fbb.CreateString(property.toDateTime().toString().toStdString()).o; 70 QByteArray ba;
71 QDataStream ds(&ba, QIODevice::WriteOnly);
72 ds << property.toDateTime();
73 return fbb.CreateString(ba.toStdString()).o;
70 } 74 }
71 return 0; 75 return 0;
72} 76}
@@ -256,8 +260,11 @@ template <>
256QVariant propertyToVariant<QDateTime>(const flatbuffers::String *property) 260QVariant propertyToVariant<QDateTime>(const flatbuffers::String *property)
257{ 261{
258 if (property) { 262 if (property) {
259 // We have to copy the memory, otherwise it would become eventually invalid 263 auto ba = QByteArray::fromRawData(property->c_str(), property->size());
260 return QDateTime::fromString(QString::fromStdString(property->c_str())); 264 QDateTime dt;
265 QDataStream ds(&ba, QIODevice::ReadOnly);
266 ds >> dt;
267 return dt;
261 } 268 }
262 return QVariant(); 269 return QVariant();
263} 270}