diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2014-08-27 11:53:47 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2015-07-13 10:36:10 +0000 |
commit | 91ab18c0c9c1ef3a44ec4a0dda98f3d44579fd89 (patch) | |
tree | 335120758ae2e69a12b6331b29b7c707f1ce29ca /src/gui/kernel/qkeysequence_p.h | |
parent | 05bcc9d2fc3aa0fd499cdf907b054707ac7bca15 (diff) |
QKeySequence: use QKeySequencePrivate::MaxKeyCount everywhere
The MaxKeyCount symbolic constant was introduced for use by QKeySequenceEdit,
but never applied to QKeySequence itself. To prevent the two from getting
out of sync, use it in the QKeySequence implementation itself, too.
This required re-writing most expressions involving QKeySequenceEditPrivate::keys
with algorithms, but we already determined in the discussion around 1cf9a139
that GCC generates the same code as the loops unrolled by hand, and if Clang
doesn't, it's its own fault.
Where using MaxKeysCount was not possible, e.g. in documentation,
static_asserts were used to indicate the need for manual changes.
Change-Id: I559fffdfd552d488448ba4a5a1ac10708c16a2ae
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/gui/kernel/qkeysequence_p.h')
-rw-r--r-- | src/gui/kernel/qkeysequence_p.h | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/gui/kernel/qkeysequence_p.h b/src/gui/kernel/qkeysequence_p.h index 97416943d0..3e4c5bae88 100644 --- a/src/gui/kernel/qkeysequence_p.h +++ b/src/gui/kernel/qkeysequence_p.h @@ -47,6 +47,8 @@ #include "qkeysequence.h" +#include <algorithm> + QT_BEGIN_NAMESPACE #ifndef QT_NO_SHORTCUT @@ -61,20 +63,17 @@ struct Q_AUTOTEST_EXPORT QKeyBinding class Q_AUTOTEST_EXPORT QKeySequencePrivate { public: - enum { MaxKeyCount = 4 }; // used in QKeySequenceEdit + enum { MaxKeyCount = 4 }; // also used in QKeySequenceEdit inline QKeySequencePrivate() : ref(1) { - key[0] = key[1] = key[2] = key[3] = 0; + std::fill_n(key, uint(MaxKeyCount), 0); } inline QKeySequencePrivate(const QKeySequencePrivate ©) : ref(1) { - key[0] = copy.key[0]; - key[1] = copy.key[1]; - key[2] = copy.key[2]; - key[3] = copy.key[3]; + std::copy(copy.key, copy.key + MaxKeyCount, key); } QAtomicInt ref; - int key[4]; + int key[MaxKeyCount]; static QString encodeString(int key, QKeySequence::SequenceFormat format); static int decodeString(const QString &keyStr, QKeySequence::SequenceFormat format); }; |