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>bb10
parent
0f923a8ce4
commit
66441d7a82
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue