QKeySequence: replace an inefficient QList with QVector

QModifKeyName is larger than a pointer, so holding it
in a QList is horribly inefficient.

Fix by marking it movable and using QVector instead.

The logic for filling the lists-turned-vectors is a bit
fishy in that it is not thread-safe. Maybe it doesn't
have to, it's not marked as \reentrant.

Change-Id: I8421e6d8b980eff022badfe3c61b3537783b5cfa
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
bb10
Marc Mutz 2014-08-15 15:25:03 +02:00
parent 4d7f528dde
commit cf0ddf24c0
1 changed files with 5 additions and 4 deletions

View File

@ -1017,9 +1017,10 @@ struct QModifKeyName {
int qt_key;
QString name;
};
Q_DECLARE_TYPEINFO(QModifKeyName, Q_MOVABLE_TYPE);
Q_GLOBAL_STATIC(QList<QModifKeyName>, globalModifs)
Q_GLOBAL_STATIC(QList<QModifKeyName>, globalPortableModifs)
Q_GLOBAL_STATIC(QVector<QModifKeyName>, globalModifs)
Q_GLOBAL_STATIC(QVector<QModifKeyName>, globalPortableModifs)
/*!
Constructs a single key from the string \a str.
@ -1035,7 +1036,7 @@ int QKeySequencePrivate::decodeString(const QString &str, QKeySequence::Sequence
QString accel = str.toLower();
bool nativeText = (format == QKeySequence::NativeText);
QList<QModifKeyName> *gmodifs;
QVector<QModifKeyName> *gmodifs;
if (nativeText) {
gmodifs = globalModifs();
if (gmodifs->isEmpty()) {
@ -1071,7 +1072,7 @@ int QKeySequencePrivate::decodeString(const QString &str, QKeySequence::Sequence
if (!gmodifs) return ret;
QList<QModifKeyName> modifs;
QVector<QModifKeyName> modifs;
if (nativeText) {
modifs << QModifKeyName(Qt::CTRL, QCoreApplication::translate("QShortcut", "Ctrl").toLower().append(QLatin1Char('+')))
<< QModifKeyName(Qt::SHIFT, QCoreApplication::translate("QShortcut", "Shift").toLower().append(QLatin1Char('+')))