summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2021-02-18 16:27:49 +0100
committerMårten Nordheim <marten.nordheim@qt.io>2021-02-25 15:45:13 +0100
commit48285b5122383ce8b4ca63c3ae098d5366883bb5 (patch)
tree13054c5b9b6dbfaa4dda3bdeef61279417364ed3 /src
parentbe93534b314084330612c350dd58e695eb569646 (diff)
Simplify deserializeQVariantList
The loop continuously removing the last element is the same as resize() (Qt5 QList didn't have a resize) Avoid constructing temporaries Write directly to the item which is in the list or construct an item in-place and then write to that. Change-Id: I89f7dae138ecebe85762b457c7e731ccbf71d6cd Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io> Reviewed-by: Brett Stottlemyer <bstottle@ford.com>
Diffstat (limited to 'src')
-rw-r--r--src/remoteobjects/qremoteobjectpacket.cpp12
1 files changed, 3 insertions, 9 deletions
diff --git a/src/remoteobjects/qremoteobjectpacket.cpp b/src/remoteobjects/qremoteobjectpacket.cpp
index bf44893..b359e79 100644
--- a/src/remoteobjects/qremoteobjectpacket.cpp
+++ b/src/remoteobjects/qremoteobjectpacket.cpp
@@ -193,28 +193,22 @@ bool deserializeQVariantList(QDataStream &s, QList<QVariant> &l)
// note: optimized version of: QDataStream operator>>(QDataStream& s, QList<T>& l)
quint32 c;
s >> c;
- const int initialListSize = l.size();
if (static_cast<quint32>(l.size()) < c)
l.reserve(c);
else if (static_cast<quint32>(l.size()) > c)
- for (int i = c; i < initialListSize; ++i)
- l.removeLast();
+ l.resize(c);
for (int i = 0; i < l.size(); ++i)
{
if (s.atEnd())
return false;
- QVariant t;
- s >> t;
- l[i] = t;
+ s >> l[i];
}
for (quint32 i = l.size(); i < c; ++i)
{
if (s.atEnd())
return false;
- QVariant t;
- s >> t;
- l.append(t);
+ s >> l.emplace_back();
}
return true;
}