diff options
Diffstat (limited to 'src/plugins')
3 files changed, 26 insertions, 22 deletions
diff --git a/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp b/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp index f8fe671a2b..a4d7e504b7 100644 --- a/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp +++ b/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp @@ -645,6 +645,6 @@ void TableGenerator::orderComposeTable() // Stable-sorting to ensure that the item that appeared before the other in the // original container will still appear first after the sort. This property is // needed to handle the cases when user re-defines already defined key sequence - std::stable_sort(m_composeTable.begin(), m_composeTable.end(), Compare()); + std::stable_sort(m_composeTable.begin(), m_composeTable.end(), ByKeys()); } diff --git a/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.h b/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.h index bf9f16b3e4..4f58358f4e 100644 --- a/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.h +++ b/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.h @@ -45,7 +45,9 @@ #include <QtCore/QMap> #include <QtCore/QString> -#define QT_KEYSEQUENCE_MAX_LEN 6 +#include <algorithm> + +static Q_CONSTEXPR int QT_KEYSEQUENCE_MAX_LEN = 6; //#define DEBUG_GENERATOR @@ -65,25 +67,30 @@ Q_DECLARE_TYPEINFO(QComposeTableElement, Q_PRIMITIVE_TYPE); QT_END_NAMESPACE #endif -class Compare +struct ByKeys { -public: - bool operator () (const QComposeTableElement &lhs, const uint rhs[QT_KEYSEQUENCE_MAX_LEN]) + using uint_array = uint[QT_KEYSEQUENCE_MAX_LEN]; + using result_type = bool; + + bool operator()(const uint_array &lhs, const uint_array &rhs) const Q_DECL_NOTHROW + { + return std::lexicographical_compare(lhs, lhs + QT_KEYSEQUENCE_MAX_LEN, + rhs, rhs + QT_KEYSEQUENCE_MAX_LEN); + } + + bool operator()(const uint_array &lhs, const QComposeTableElement &rhs) const Q_DECL_NOTHROW + { + return operator()(lhs, rhs.keys); + } + + bool operator()(const QComposeTableElement &lhs, const uint_array &rhs) const Q_DECL_NOTHROW { - for (size_t i = 0; i < QT_KEYSEQUENCE_MAX_LEN; i++) { - if (lhs.keys[i] != rhs[i]) - return (lhs.keys[i] < rhs[i]); - } - return false; + return operator()(lhs.keys, rhs); } - bool operator () (const QComposeTableElement &lhs, const QComposeTableElement &rhs) + bool operator()(const QComposeTableElement &lhs, const QComposeTableElement &rhs) const Q_DECL_NOTHROW { - for (size_t i = 0; i < QT_KEYSEQUENCE_MAX_LEN; i++) { - if (lhs.keys[i] != rhs.keys[i]) - return (lhs.keys[i] < rhs.keys[i]); - } - return false; + return operator()(lhs.keys, rhs.keys); } }; diff --git a/src/plugins/platforminputcontexts/compose/qcomposeplatforminputcontext.cpp b/src/plugins/platforminputcontexts/compose/qcomposeplatforminputcontext.cpp index 857f437661..6016d460fc 100644 --- a/src/plugins/platforminputcontexts/compose/qcomposeplatforminputcontext.cpp +++ b/src/plugins/platforminputcontexts/compose/qcomposeplatforminputcontext.cpp @@ -155,11 +155,8 @@ void QComposeInputContext::update(Qt::InputMethodQueries q) static bool isDuplicate(const QComposeTableElement &lhs, const QComposeTableElement &rhs) { - for (size_t i = 0; i < QT_KEYSEQUENCE_MAX_LEN; i++) { - if (lhs.keys[i] != rhs.keys[i]) - return false; - } - return true; + return std::equal(lhs.keys, lhs.keys + QT_KEYSEQUENCE_MAX_LEN, + QT_MAKE_CHECKED_ARRAY_ITERATOR(rhs.keys, QT_KEYSEQUENCE_MAX_LEN)); } bool QComposeInputContext::checkComposeTable() @@ -182,7 +179,7 @@ bool QComposeInputContext::checkComposeTable() } Q_ASSERT(!m_composeTable.isEmpty()); QVector<QComposeTableElement>::const_iterator it = - std::lower_bound(m_composeTable.constBegin(), m_composeTable.constEnd(), m_composeBuffer, Compare()); + std::lower_bound(m_composeTable.constBegin(), m_composeTable.constEnd(), m_composeBuffer, ByKeys()); // prevent dereferencing an 'end' iterator, which would result in a crash if (it == m_composeTable.constEnd()) |