QKeySequence: let Private::decodeString() take QString by value
It calls toLower() on it, and the existence of two strings in scope has already caused some latent bug where sizes of the two were mixed. Taking by value means we can use the rvalue-version of toLower(). While that does not guarantee no allocations, we can make sure that at least in QKeySequence::assign(), we hand in unshared data, by using std::move(). Change-Id: Ic4a18486a6f4528eba36109dec1a47082cf57055 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
parent
4088f4ce4d
commit
29a459d7cc
@ -1008,7 +1008,6 @@ int QKeySequence::assign(const QString &ks)
|
||||
int QKeySequence::assign(const QString &ks, QKeySequence::SequenceFormat format)
|
||||
{
|
||||
QString keyseq = ks;
|
||||
QString part;
|
||||
int n = 0;
|
||||
int p = 0, diff = 0;
|
||||
|
||||
@ -1033,9 +1032,9 @@ int QKeySequence::assign(const QString &ks, QKeySequence::SequenceFormat format)
|
||||
}
|
||||
}
|
||||
}
|
||||
part = keyseq.left(-1 == p ? keyseq.length() : p - diff);
|
||||
QString part = keyseq.left(-1 == p ? keyseq.length() : p - diff);
|
||||
keyseq = keyseq.right(-1 == p ? 0 : keyseq.length() - (p + 1));
|
||||
d->key[n] = QKeySequencePrivate::decodeString(part, format);
|
||||
d->key[n] = QKeySequencePrivate::decodeString(std::move(part), format);
|
||||
++n;
|
||||
}
|
||||
return n;
|
||||
@ -1061,10 +1060,10 @@ int QKeySequence::decodeString(const QString &str)
|
||||
return QKeySequencePrivate::decodeString(str, NativeText);
|
||||
}
|
||||
|
||||
int QKeySequencePrivate::decodeString(const QString &str, QKeySequence::SequenceFormat format)
|
||||
int QKeySequencePrivate::decodeString(QString accel, QKeySequence::SequenceFormat format)
|
||||
{
|
||||
int ret = 0;
|
||||
QString accel = str.toLower();
|
||||
accel = std::move(accel).toLower();
|
||||
bool nativeText = (format == QKeySequence::NativeText);
|
||||
|
||||
QVector<QModifKeyName> *gmodifs;
|
||||
|
@ -85,7 +85,7 @@ public:
|
||||
static QString encodeString(int key, QKeySequence::SequenceFormat format);
|
||||
// used in dbusmenu
|
||||
Q_GUI_EXPORT static QString keyName(int key, QKeySequence::SequenceFormat format);
|
||||
static int decodeString(const QString &keyStr, QKeySequence::SequenceFormat format);
|
||||
static int decodeString(QString accel, QKeySequence::SequenceFormat format);
|
||||
};
|
||||
#endif // QT_NO_SHORTCUT
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user