summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qstring.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2018-05-25 16:33:48 -0300
committerThiago Macieira <thiago.macieira@intel.com>2018-07-04 03:04:40 +0000
commitd0427759c67704fe0f1b04edadd4d30329af268c (patch)
treebe555a72712a68658dd907fc600f03385df8e2cf /src/corelib/tools/qstring.cpp
parentc053f9d15467459477ccbbe156a096e3ac5e3a91 (diff)
Add qbswap for a memory region
The compiler was generating some vectorized code for qresource.cpp but it wasn't very efficient. So improve upon it and make use in other places where we read UTF-16BE strings. [ChangeLog][QtCore] Added an overload of q{To,From}{Big,Little}Endian that operates on a memory region. Change-Id: I6a540578e810472bb455fffd1531fa2f1d724dfc Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/corelib/tools/qstring.cpp')
-rw-r--r--src/corelib/tools/qstring.cpp11
1 files changed, 2 insertions, 9 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index d3a6851e2c..650c3bdb32 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -9946,11 +9946,7 @@ QDataStream &operator<<(QDataStream &out, const QString &str)
out.writeBytes(reinterpret_cast<const char *>(str.unicode()), sizeof(QChar) * str.length());
} else {
QVarLengthArray<ushort> buffer(str.length());
- const ushort *data = reinterpret_cast<const ushort *>(str.constData());
- for (int i = 0; i < str.length(); i++) {
- buffer[i] = qbswap(*data);
- ++data;
- }
+ qbswap<sizeof(ushort)>(str.constData(), str.length(), buffer.data());
out.writeBytes(reinterpret_cast<const char *>(buffer.data()), sizeof(ushort) * buffer.size());
}
} else {
@@ -10007,10 +10003,7 @@ QDataStream &operator>>(QDataStream &in, QString &str)
if ((in.byteOrder() == QDataStream::BigEndian)
!= (QSysInfo::ByteOrder == QSysInfo::BigEndian)) {
ushort *data = reinterpret_cast<ushort *>(str.data());
- while (len--) {
- *data = qbswap(*data);
- ++data;
- }
+ qbswap<sizeof(*data)>(data, len, data);
}
} else {
str = QString(QLatin1String(""));