Micro-optimize QKeySequence datastream operator (I)

Instead of creating a QList with the keys with one of two statically
known sizes, stream the contents itself. Apart from QDataStream,
this no longer allocates any memory.

Change-Id: I5ed814b186dcaf8cc7dedcc520928aefab01f009
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Marc Mutz 2014-08-27 00:00:03 +02:00
parent 3290330d44
commit 862b1b3ceb
1 changed files with 7 additions and 8 deletions

View File

@ -1577,15 +1577,14 @@ QString QKeySequence::listToString(const QList<QKeySequence> &list, SequenceForm
*/
QDataStream &operator<<(QDataStream &s, const QKeySequence &keysequence)
{
QList<quint32> list;
list << keysequence.d->key[0];
if (s.version() >= 5 && keysequence.count() > 1) {
list << keysequence.d->key[1];
list << keysequence.d->key[2];
list << keysequence.d->key[3];
Q_STATIC_ASSERT_X(QKeySequencePrivate::MaxKeyCount == 4, "Forgot to adapt QDataStream &operator<<(QDataStream &s, const QKeySequence &keysequence) to new QKeySequence::MaxKeyCount");
const bool extended = s.version() >= 5 && keysequence.count() > 1;
s << quint32(extended ? 4 : 1) << quint32(keysequence.d->key[0]);
if (extended) {
s << quint32(keysequence.d->key[1])
<< quint32(keysequence.d->key[2])
<< quint32(keysequence.d->key[3]);
}
s << list;
return s;
}