From 85a4d5ac9561b639c47721e4e2305b6ced6be261 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 12 May 2017 14:26:07 +0200 Subject: QDateTime::toString is really slow --- common/propertymapper.cpp | 13 ++++++++++--- common/typeindex.cpp | 8 ++++---- 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'common') 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 @@ #include "applicationdomaintype.h" #include +#include #include "mail_generated.h" #include "contact_generated.h" @@ -66,7 +67,10 @@ template <> flatbuffers::uoffset_t variantToProperty(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) { if (property.isValid()) { - return fbb.CreateString(property.toDateTime().toString().toStdString()).o; + QByteArray ba; + QDataStream ds(&ba, QIODevice::WriteOnly); + ds << property.toDateTime(); + return fbb.CreateString(ba.toStdString()).o; } return 0; } @@ -256,8 +260,11 @@ template <> QVariant propertyToVariant(const flatbuffers::String *property) { if (property) { - // We have to copy the memory, otherwise it would become eventually invalid - return QDateTime::fromString(QString::fromStdString(property->c_str())); + auto ba = QByteArray::fromRawData(property->c_str(), property->size()); + QDateTime dt; + QDataStream ds(&ba, QIODevice::ReadOnly); + ds >> dt; + return dt; } return QVariant(); } 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 @@ #include "log.h" #include "index.h" #include +#include using namespace Sink; static QByteArray getByteArray(const QVariant &value) { if (value.type() == QVariant::DateTime) { - const auto result = value.toDateTime().toString().toLatin1(); - if (result.isEmpty()) { - return "nodate"; - } + QByteArray result; + QDataStream ds(&result, QIODevice::WriteOnly); + ds << value.toDateTime(); return result; } if (value.type() == QVariant::Bool) { -- cgit v1.2.3