diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2018-01-22 19:29:04 -0800 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2018-06-18 19:53:24 +0000 |
commit | 48d6990e418cffb09cd76c0d48b8ffa63490d6cf (patch) | |
tree | f426654751b0b68f7a166ce2b66344cebd75193f /src/corelib/serialization/qcborvalue.cpp | |
parent | 40d528d9fd9a4ce3b97f79b31545e7709a5d3588 (diff) |
QCborValue: store US-ASCII strings as 8-bit
They're easy to convert back to UTF-16, their length is the same, they
occupy half the memory and they're easy to encode into CBOR (no
transformation necessary).
The code was copied from QJsonPrivate::Latin1String::operator=().
Change-Id: I56b444f9d6274221a3b7fffd150c52bcb6c97f37
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/serialization/qcborvalue.cpp')
-rw-r--r-- | src/corelib/serialization/qcborvalue.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/corelib/serialization/qcborvalue.cpp b/src/corelib/serialization/qcborvalue.cpp index 96d3feaf1b..970ae23352 100644 --- a/src/corelib/serialization/qcborvalue.cpp +++ b/src/corelib/serialization/qcborvalue.cpp @@ -48,6 +48,7 @@ #include <qlocale.h> #include <private/qnumeric_p.h> #include <qscopedvaluerollback.h> +#include <private/qsimd_p.h> #include <qstack.h> #include <new> @@ -1082,6 +1083,24 @@ void QCborContainerPrivate::replaceAt_complex(Element &e, const QCborValue &valu } } +// in qstring.cpp +void qt_to_latin1_unchecked(uchar *dst, const ushort *uc, qsizetype len); + +Q_NEVER_INLINE void QCborContainerPrivate::appendAsciiString(const QString &s) +{ + qsizetype len = s.size(); + QtCbor::Element e; + e.value = addByteData(nullptr, len); + e.type = QCborValue::String; + e.flags = Element::HasByteData | Element::StringIsAscii; + elements.append(e); + + char *ptr = data.data() + e.value + sizeof(ByteData); + uchar *l = reinterpret_cast<uchar *>(ptr); + const ushort *uc = (const ushort *)s.unicode(); + qt_to_latin1_unchecked(l, uc, len); +} + QT_WARNING_DISABLE_MSVC(4146) // unary minus operator applied to unsigned type, result still unsigned static int compareContainer(const QCborContainerPrivate *c1, const QCborContainerPrivate *c2); static int compareElementNoData(const Element &e1, const Element &e2) |