Fixes (#122)
* Prevent a possible C++11 range for detach The solution with Qt>=5.7 is to use the qAsConst() macro. But the qAsConst macro is just a const_cast to const T&. * Don't call QByteArray::operator[]() on temporary Just use the QByteArray::at(). * Adds missing reference in foreach That's an non non trivial type (QString), using a reference as no drawbacks and it performs better. * Use QStringList::constFirst() Drop QStringList::first(). It's faster and we might avoid detaching a temporary. * Don't call QList::operator[]() on temporary objects It's not what we want. The at operator and QList::value() do the job in the right way. * Stops allocating an unneeded temporary container We were allocating an temporary container (_entries.values(keyCode)) which implies an extra iteration also. Now we don't use any temporary container and only perform one iteration.
This commit is contained in:
@@ -543,27 +543,27 @@ QList<KeyboardTranslatorReader::Token> KeyboardTranslatorReader::tokenize(const
|
||||
if ( title.exactMatch(text) )
|
||||
{
|
||||
Token titleToken = { Token::TitleKeyword , QString() };
|
||||
Token textToken = { Token::TitleText , title.capturedTexts()[1] };
|
||||
Token textToken = { Token::TitleText , title.capturedTexts().at(1) };
|
||||
|
||||
list << titleToken << textToken;
|
||||
}
|
||||
else if ( key.exactMatch(text) )
|
||||
{
|
||||
Token keyToken = { Token::KeyKeyword , QString() };
|
||||
Token sequenceToken = { Token::KeySequence , key.capturedTexts()[1].remove(' ') };
|
||||
Token sequenceToken = { Token::KeySequence , key.capturedTexts().value(1).remove(' ') };
|
||||
|
||||
list << keyToken << sequenceToken;
|
||||
|
||||
if ( key.capturedTexts()[3].isEmpty() )
|
||||
if ( key.capturedTexts().at(3).isEmpty() )
|
||||
{
|
||||
// capturedTexts()[2] is a command
|
||||
Token commandToken = { Token::Command , key.capturedTexts()[2] };
|
||||
Token commandToken = { Token::Command , key.capturedTexts().at(2) };
|
||||
list << commandToken;
|
||||
}
|
||||
else
|
||||
{
|
||||
// capturedTexts()[3] is the output string
|
||||
Token outputToken = { Token::OutputText , key.capturedTexts()[3] };
|
||||
Token outputToken = { Token::OutputText , key.capturedTexts().at(3) };
|
||||
list << outputToken;
|
||||
}
|
||||
}
|
||||
@@ -852,10 +852,11 @@ void KeyboardTranslator::removeEntry(const Entry& entry)
|
||||
}
|
||||
KeyboardTranslator::Entry KeyboardTranslator::findEntry(int keyCode, Qt::KeyboardModifiers modifiers, States state) const
|
||||
{
|
||||
foreach(const Entry& entry, _entries.values(keyCode))
|
||||
for (auto it = _entries.cbegin(), end = _entries.cend(); it != end; ++it)
|
||||
{
|
||||
if ( entry.matches(keyCode,modifiers,state) )
|
||||
return entry;
|
||||
if (it.key() == keyCode)
|
||||
if ( it.value().matches(keyCode,modifiers,state) )
|
||||
return *it;
|
||||
}
|
||||
return Entry(); // entry not found
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user