summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-12-03 13:06:12 +0100
committerLiang Qi <liang.qi@theqtcompany.com>2015-12-19 07:41:50 +0000
commit66441d7a828ddcdae709cf4699420147f376bdcd (patch)
treefc16433f11c0eb8dd05971566528c70686a72dcc
parent0f923a8ce45a0b9379bf0a43e68897a3a8333fda (diff)
Make use of new QHash::erase(const_iterator) overload
Drive-by changes: - use auto for iterators - add Q_UNLIKELY for conditions leading to a qWarning etc Change-Id: Iff8f36d67c96674d354a501b26640f73c15ce58d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Sérgio Martins <iamsergio@gmail.com>
-rw-r--r--src/corelib/itemmodels/qabstractitemmodel.cpp22
-rw-r--r--src/corelib/itemmodels/qabstractitemmodel_p.h4
-rw-r--r--src/corelib/statemachine/qstatemachine.cpp5
-rw-r--r--src/corelib/tools/qsharedpointer.cpp8
-rw-r--r--src/gui/text/qabstracttextdocumentlayout.cpp4
-rw-r--r--src/network/access/qnetworkdiskcache.cpp4
-rw-r--r--src/widgets/itemviews/qabstractitemview.cpp5
-rw-r--r--src/widgets/itemviews/qitemeditorfactory.cpp4
-rw-r--r--src/widgets/widgets/qwidgetanimator.cpp4
-rw-r--r--src/widgets/widgets/qwidgettextcontrol.cpp4
10 files changed, 31 insertions, 33 deletions
diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp
index 90297b9115..38a7bff182 100644
--- a/src/corelib/itemmodels/qabstractitemmodel.cpp
+++ b/src/corelib/itemmodels/qabstractitemmodel.cpp
@@ -607,7 +607,7 @@ void QAbstractItemModelPrivate::rowsInserted(const QModelIndex &parent,
it != persistent_moved.constEnd(); ++it) {
QPersistentModelIndexData *data = *it;
QModelIndex old = data->index;
- persistent.indexes.erase(persistent.indexes.find(old));
+ persistent.indexes.erase(persistent.indexes.constFind(old));
data->index = q_func()->index(old.row() + count, old.column(), parent);
if (data->index.isValid()) {
persistent.insertMultiAtEnd(data->index, data);
@@ -700,7 +700,7 @@ void QAbstractItemModelPrivate::movePersistentIndexes(const QVector<QPersistentM
else
column += change;
- persistent.indexes.erase(persistent.indexes.find(data->index));
+ persistent.indexes.erase(persistent.indexes.constFind(data->index));
data->index = q_func()->index(row, column, parent);
if (data->index.isValid()) {
persistent.insertMultiAtEnd(data->index, data);
@@ -767,7 +767,7 @@ void QAbstractItemModelPrivate::rowsRemoved(const QModelIndex &parent,
it != persistent_moved.constEnd(); ++it) {
QPersistentModelIndexData *data = *it;
QModelIndex old = data->index;
- persistent.indexes.erase(persistent.indexes.find(old));
+ persistent.indexes.erase(persistent.indexes.constFind(old));
data->index = q_func()->index(old.row() - count, old.column(), parent);
if (data->index.isValid()) {
persistent.insertMultiAtEnd(data->index, data);
@@ -779,7 +779,7 @@ void QAbstractItemModelPrivate::rowsRemoved(const QModelIndex &parent,
for (QVector<QPersistentModelIndexData *>::const_iterator it = persistent_invalidated.constBegin();
it != persistent_invalidated.constEnd(); ++it) {
QPersistentModelIndexData *data = *it;
- persistent.indexes.erase(persistent.indexes.find(data->index));
+ persistent.indexes.erase(persistent.indexes.constFind(data->index));
data->index = QModelIndex();
data->model = 0;
}
@@ -812,7 +812,7 @@ void QAbstractItemModelPrivate::columnsInserted(const QModelIndex &parent,
it != persistent_moved.constEnd(); ++it) {
QPersistentModelIndexData *data = *it;
QModelIndex old = data->index;
- persistent.indexes.erase(persistent.indexes.find(old));
+ persistent.indexes.erase(persistent.indexes.constFind(old));
data->index = q_func()->index(old.row(), old.column() + count, parent);
if (data->index.isValid()) {
persistent.insertMultiAtEnd(data->index, data);
@@ -862,7 +862,7 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent,
it != persistent_moved.constEnd(); ++it) {
QPersistentModelIndexData *data = *it;
QModelIndex old = data->index;
- persistent.indexes.erase(persistent.indexes.find(old));
+ persistent.indexes.erase(persistent.indexes.constFind(old));
data->index = q_func()->index(old.row(), old.column() - count, parent);
if (data->index.isValid()) {
persistent.insertMultiAtEnd(data->index, data);
@@ -874,7 +874,7 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent,
for (QVector<QPersistentModelIndexData *>::const_iterator it = persistent_invalidated.constBegin();
it != persistent_invalidated.constEnd(); ++it) {
QPersistentModelIndexData *data = *it;
- persistent.indexes.erase(persistent.indexes.find(data->index));
+ persistent.indexes.erase(persistent.indexes.constFind(data->index));
data->index = QModelIndex();
data->model = 0;
}
@@ -3160,8 +3160,8 @@ void QAbstractItemModel::changePersistentIndex(const QModelIndex &from, const QM
if (d->persistent.indexes.isEmpty())
return;
// find the data and reinsert it sorted
- const QHash<QModelIndex, QPersistentModelIndexData *>::iterator it = d->persistent.indexes.find(from);
- if (it != d->persistent.indexes.end()) {
+ const auto it = d->persistent.indexes.constFind(from);
+ if (it != d->persistent.indexes.cend()) {
QPersistentModelIndexData *data = *it;
d->persistent.indexes.erase(it);
data->index = to;
@@ -3194,8 +3194,8 @@ void QAbstractItemModel::changePersistentIndexList(const QModelIndexList &from,
for (int i = 0; i < from.count(); ++i) {
if (from.at(i) == to.at(i))
continue;
- const QHash<QModelIndex, QPersistentModelIndexData *>::iterator it = d->persistent.indexes.find(from.at(i));
- if (it != d->persistent.indexes.end()) {
+ const auto it = d->persistent.indexes.constFind(from.at(i));
+ if (it != d->persistent.indexes.cend()) {
QPersistentModelIndexData *data = *it;
d->persistent.indexes.erase(it);
data->index = to.at(i);
diff --git a/src/corelib/itemmodels/qabstractitemmodel_p.h b/src/corelib/itemmodels/qabstractitemmodel_p.h
index 77a3164959..84763dff0d 100644
--- a/src/corelib/itemmodels/qabstractitemmodel_p.h
+++ b/src/corelib/itemmodels/qabstractitemmodel_p.h
@@ -117,8 +117,8 @@ public:
To be used before an index is invalided
*/
inline void invalidatePersistentIndex(const QModelIndex &index) {
- QHash<QModelIndex, QPersistentModelIndexData *>::iterator it = persistent.indexes.find(index);
- if(it != persistent.indexes.end()) {
+ const auto it = persistent.indexes.constFind(index);
+ if (it != persistent.indexes.cend()) {
QPersistentModelIndexData *data = *it;
persistent.indexes.erase(it);
data->index = QModelIndex();
diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp
index 20d5ed890b..0ce3ecc30e 100644
--- a/src/corelib/statemachine/qstatemachine.cpp
+++ b/src/corelib/statemachine/qstatemachine.cpp
@@ -1341,9 +1341,8 @@ void QStateMachinePrivate::unregisterRestorables(const QList<QAbstractState *> &
if (it == registeredRestorablesForState.end())
continue;
QHash<RestorableId, QVariant> &restorables = it.value();
- QHash<RestorableId, QVariant>::iterator it2;
- it2 = restorables.find(id);
- if (it2 == restorables.end())
+ const auto it2 = restorables.constFind(id);
+ if (it2 == restorables.cend())
continue;
#ifdef QSTATEMACHINE_RESTORE_PROPERTIES_DEBUG
qDebug() << q_func() << ": unregistered for" << s;
diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp
index b5e27cc720..24eee1d1b8 100644
--- a/src/corelib/tools/qsharedpointer.cpp
+++ b/src/corelib/tools/qsharedpointer.cpp
@@ -1538,15 +1538,15 @@ void QtSharedPointer::internalSafetyCheckRemove(const void *d_ptr)
QMutexLocker lock(&kp->mutex);
- QHash<const void *, Data>::iterator it = kp->dPointers.find(d_ptr);
- if (Q_UNLIKELY(it == kp->dPointers.end())) {
+ const auto it = kp->dPointers.constFind(d_ptr);
+ if (Q_UNLIKELY(it == kp->dPointers.cend())) {
qFatal("QSharedPointer: internal self-check inconsistency: pointer %p was not tracked. "
"To use QT_SHAREDPOINTER_TRACK_POINTERS, you have to enable it throughout "
"in your code.", d_ptr);
}
- QHash<const volatile void *, const void *>::iterator it2 = kp->dataPointers.find(it->pointer);
- Q_ASSERT(it2 != kp->dataPointers.end());
+ const auto it2 = kp->dataPointers.constFind(it->pointer);
+ Q_ASSERT(it2 != kp->dataPointers.cend());
//qDebug("Removing d=%p value=%p", d_ptr, it->pointer);
diff --git a/src/gui/text/qabstracttextdocumentlayout.cpp b/src/gui/text/qabstracttextdocumentlayout.cpp
index 7735fd6b46..ea6c5d1984 100644
--- a/src/gui/text/qabstracttextdocumentlayout.cpp
+++ b/src/gui/text/qabstracttextdocumentlayout.cpp
@@ -447,8 +447,8 @@ void QAbstractTextDocumentLayout::unregisterHandler(int objectType, QObject *com
{
Q_D(QAbstractTextDocumentLayout);
- HandlerHash::iterator it = d->handlers.find(objectType);
- if (it != d->handlers.end() && (!component || component == it->component)) {
+ const auto it = d->handlers.constFind(objectType);
+ if (it != d->handlers.cend() && (!component || component == it->component)) {
if (component)
disconnect(component, SIGNAL(destroyed(QObject*)), this, SLOT(_q_handlerDestroyed(QObject*)));
d->handlers.erase(it);
diff --git a/src/network/access/qnetworkdiskcache.cpp b/src/network/access/qnetworkdiskcache.cpp
index 3f705450dd..5988c34433 100644
--- a/src/network/access/qnetworkdiskcache.cpp
+++ b/src/network/access/qnetworkdiskcache.cpp
@@ -231,8 +231,8 @@ void QNetworkDiskCache::insert(QIODevice *device)
qDebug() << "QNetworkDiskCache::insert()" << device;
#endif
Q_D(QNetworkDiskCache);
- QHash<QIODevice*, QCacheItem*>::iterator it = d->inserting.find(device);
- if (it == d->inserting.end()) {
+ const auto it = d->inserting.constFind(device);
+ if (Q_UNLIKELY(it == d->inserting.cend())) {
qWarning() << "QNetworkDiskCache::insert() called on a device we don't know about" << device;
return;
}
diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp
index cbf734203a..edfb5c0f57 100644
--- a/src/widgets/itemviews/qabstractitemview.cpp
+++ b/src/widgets/itemviews/qabstractitemview.cpp
@@ -4290,9 +4290,8 @@ QModelIndex QAbstractItemViewPrivate::indexForEditor(QWidget *editor) const
void QAbstractItemViewPrivate::removeEditor(QWidget *editor)
{
- QEditorIndexHash::iterator it = editorIndexHash.find(editor);
- if (it != editorIndexHash.end())
- {
+ const auto it = editorIndexHash.constFind(editor);
+ if (it != editorIndexHash.cend()) {
indexEditorHash.remove(it.value());
editorIndexHash.erase(it);
}
diff --git a/src/widgets/itemviews/qitemeditorfactory.cpp b/src/widgets/itemviews/qitemeditorfactory.cpp
index 701e7ab79b..3287d5dc99 100644
--- a/src/widgets/itemviews/qitemeditorfactory.cpp
+++ b/src/widgets/itemviews/qitemeditorfactory.cpp
@@ -198,8 +198,8 @@ QItemEditorFactory::~QItemEditorFactory()
*/
void QItemEditorFactory::registerEditor(int userType, QItemEditorCreatorBase *creator)
{
- QHash<int, QItemEditorCreatorBase *>::iterator it = creatorMap.find(userType);
- if (it != creatorMap.end()) {
+ const auto it = creatorMap.constFind(userType);
+ if (it != creatorMap.cend()) {
QItemEditorCreatorBase *oldCreator = it.value();
Q_ASSERT(oldCreator);
creatorMap.erase(it);
diff --git a/src/widgets/widgets/qwidgetanimator.cpp b/src/widgets/widgets/qwidgetanimator.cpp
index 2bed11289f..3dc0e9a673 100644
--- a/src/widgets/widgets/qwidgetanimator.cpp
+++ b/src/widgets/widgets/qwidgetanimator.cpp
@@ -47,8 +47,8 @@ QWidgetAnimator::QWidgetAnimator(QMainWindowLayout *layout) : m_mainWindowLayout
void QWidgetAnimator::abort(QWidget *w)
{
#ifndef QT_NO_ANIMATION
- AnimationMap::iterator it = m_animation_map.find(w);
- if (it == m_animation_map.end())
+ const auto it = m_animation_map.constFind(w);
+ if (it == m_animation_map.cend())
return;
QPropertyAnimation *anim = *it;
m_animation_map.erase(it);
diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp
index deca002bf5..1c249eee78 100644
--- a/src/widgets/widgets/qwidgettextcontrol.cpp
+++ b/src/widgets/widgets/qwidgettextcontrol.cpp
@@ -2401,8 +2401,8 @@ void QWidgetTextControl::setExtraSelections(const QList<QTextEdit::ExtraSelectio
for (int i = 0; i < selections.count(); ++i) {
const QTextEdit::ExtraSelection &sel = selections.at(i);
- QHash<int, int>::iterator it = hash.find(sel.cursor.anchor());
- if (it != hash.end()) {
+ const auto it = hash.constFind(sel.cursor.anchor());
+ if (it != hash.cend()) {
const QAbstractTextDocumentLayout::Selection &esel = d->extraSelections.at(it.value());
if (esel.cursor.position() == sel.cursor.position()
&& esel.format == sel.format) {