diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-05-12 14:26:07 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-05-12 14:26:07 +0200 |
commit | 85a4d5ac9561b639c47721e4e2305b6ced6be261 (patch) | |
tree | bf75b2e6938121c0165bdc14081582fbc33de0de | |
parent | b9af56291f5bfc898ce232b4ebf5065554484962 (diff) | |
download | sink-85a4d5ac9561b639c47721e4e2305b6ced6be261.tar.gz sink-85a4d5ac9561b639c47721e4e2305b6ced6be261.zip |
QDateTime::toString is really slow
-rw-r--r-- | common/propertymapper.cpp | 13 | ||||
-rw-r--r-- | common/typeindex.cpp | 8 |
2 files changed, 14 insertions, 7 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 <> | |||
66 | flatbuffers::uoffset_t variantToProperty<QDateTime>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) | 67 | flatbuffers::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 <> | |||
256 | QVariant propertyToVariant<QDateTime>(const flatbuffers::String *property) | 260 | QVariant 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 | } |
diff --git a/common/typeindex.cpp b/common/typeindex.cpp index b8845b7..113c209 100644 --- a/common/typeindex.cpp +++ b/common/typeindex.cpp | |||
@@ -21,16 +21,16 @@ | |||
21 | #include "log.h" | 21 | #include "log.h" |
22 | #include "index.h" | 22 | #include "index.h" |
23 | #include <QDateTime> | 23 | #include <QDateTime> |
24 | #include <QDataStream> | ||
24 | 25 | ||
25 | using namespace Sink; | 26 | using namespace Sink; |
26 | 27 | ||
27 | static QByteArray getByteArray(const QVariant &value) | 28 | static QByteArray getByteArray(const QVariant &value) |
28 | { | 29 | { |
29 | if (value.type() == QVariant::DateTime) { | 30 | if (value.type() == QVariant::DateTime) { |
30 | const auto result = value.toDateTime().toString().toLatin1(); | 31 | QByteArray result; |
31 | if (result.isEmpty()) { | 32 | QDataStream ds(&result, QIODevice::WriteOnly); |
32 | return "nodate"; | 33 | ds << value.toDateTime(); |
33 | } | ||
34 | return result; | 34 | return result; |
35 | } | 35 | } |
36 | if (value.type() == QVariant::Bool) { | 36 | if (value.type() == QVariant::Bool) { |