aboutsummaryrefslogtreecommitdiffstats
path: root/src/virtualkeyboard/inputengine.cpp
diff options
context:
space:
mode:
authorAnton Kudryavtsev <a.kudryavtsev@netris.ru>2016-03-21 11:18:41 +0300
committerMitch Curtis <mitch.curtis@theqtcompany.com>2016-03-22 07:03:45 +0000
commit13bb78fe4535eff234db981c83af1b2293989ade (patch)
treed6319f62b41b78f39af4b8938378a0955a13e97e /src/virtualkeyboard/inputengine.cpp
parent39de28437096ba9c8d9f9227625ac26210145f2d (diff)
Don't perform lookup twice with associative containers
Change-Id: I58be9a4e57ed1cc8d9aaf6c26be517263f8c73c3 Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
Diffstat (limited to 'src/virtualkeyboard/inputengine.cpp')
-rw-r--r--src/virtualkeyboard/inputengine.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/virtualkeyboard/inputengine.cpp b/src/virtualkeyboard/inputengine.cpp
index d27fc57e..9f3d037b 100644
--- a/src/virtualkeyboard/inputengine.cpp
+++ b/src/virtualkeyboard/inputengine.cpp
@@ -375,13 +375,14 @@ void InputEngine::setInputMethod(AbstractInputMethod *inputMethod)
const QList<SelectionListModel::Type> activeSelectionLists = d->inputMethod->selectionLists();
QList<SelectionListModel::Type> inactiveSelectionLists = d->selectionListModels.keys();
for (const SelectionListModel::Type &selectionListType : activeSelectionLists) {
- if (!d->selectionListModels.contains(selectionListType)) {
- d->selectionListModels[selectionListType] = new SelectionListModel(this);
+ auto it = d->selectionListModels.find(selectionListType);
+ if (it == d->selectionListModels.end()) {
+ it = d->selectionListModels.insert(selectionListType, new SelectionListModel(this));
if (selectionListType == SelectionListModel::WordCandidateList) {
emit wordCandidateListModelChanged();
}
}
- d->selectionListModels[selectionListType]->setDataSource(inputMethod, selectionListType);
+ it.value()->setDataSource(inputMethod, selectionListType);
if (selectionListType == SelectionListModel::WordCandidateList) {
emit wordCandidateListVisibleHintChanged();
}
@@ -390,8 +391,9 @@ void InputEngine::setInputMethod(AbstractInputMethod *inputMethod)
// Deallocate inactive selection lists
for (const SelectionListModel::Type &selectionListType : qAsConst(inactiveSelectionLists)) {
- if (d->selectionListModels.contains(selectionListType)) {
- d->selectionListModels[selectionListType]->setDataSource(0, selectionListType);
+ const auto it = d->selectionListModels.constFind(selectionListType);
+ if (it != d->selectionListModels.cend()) {
+ it.value()->setDataSource(0, selectionListType);
if (selectionListType == SelectionListModel::WordCandidateList) {
emit wordCandidateListVisibleHintChanged();
}
@@ -458,9 +460,10 @@ SelectionListModel *InputEngine::wordCandidateListModel() const
bool InputEngine::wordCandidateListVisibleHint() const
{
Q_D(const InputEngine);
- if (!d->selectionListModels.contains(SelectionListModel::WordCandidateList))
+ const auto it = d->selectionListModels.constFind(SelectionListModel::WordCandidateList);
+ if (it == d->selectionListModels.cend())
return false;
- return d->selectionListModels[SelectionListModel::WordCandidateList]->dataSource() != 0;
+ return it.value()->dataSource() != 0;
}
/*!