Use (new) erase()/erase_if() algorithms
Change-Id: I45c18fd45c20b226e44d16315e3ebb6c305d4ab0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
f19266bd02
commit
105a66e654
@ -113,6 +113,7 @@ qt_internal_add_tool(${target_name}
|
||||
../src/corelib/time/qgregoriancalendar.cpp ../src/corelib/time/qgregoriancalendar_p.h # special case
|
||||
../src/corelib/time/qromancalendar.cpp ../src/corelib/time/qromancalendar_p.h # special case
|
||||
../src/corelib/time/qdatetime.cpp ../src/corelib/time/qdatetime.h ../src/corelib/time/qdatetime_p.h # special case
|
||||
../src/corelib/tools/qduplicatetracker_p.h
|
||||
../src/corelib/tools/qhash.cpp ../src/corelib/tools/qhash.h
|
||||
../src/corelib/tools/qlist.h
|
||||
../src/corelib/tools/qmap.h
|
||||
|
@ -940,9 +940,7 @@ MakefileGenerator::filterIncludedFiles(const char *var)
|
||||
auto isIncluded = [this](const ProString &input) {
|
||||
return QMakeSourceFileInfo::included(input.toQString()) > 0;
|
||||
};
|
||||
inputs.erase(std::remove_if(inputs.begin(), inputs.end(),
|
||||
isIncluded),
|
||||
inputs.end());
|
||||
inputs.removeIf(isIncluded);
|
||||
}
|
||||
|
||||
static QString
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include <qset.h>
|
||||
#include <qstringlist.h>
|
||||
#include <qtextstream.h>
|
||||
#include <private/qduplicatetracker_p.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
@ -403,21 +404,9 @@ void ProStringList::removeEmpty()
|
||||
|
||||
void ProStringList::removeDuplicates()
|
||||
{
|
||||
int n = size();
|
||||
int j = 0;
|
||||
QSet<ProString> seen;
|
||||
seen.reserve(n);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
const ProString &s = at(i);
|
||||
if (seen.contains(s))
|
||||
continue;
|
||||
seen.insert(s);
|
||||
if (j != i)
|
||||
(*this)[j] = s;
|
||||
++j;
|
||||
}
|
||||
if (n != j)
|
||||
erase(begin() + j, end());
|
||||
QDuplicateTracker<ProString> seen;
|
||||
seen.reserve(size());
|
||||
removeIf([&](const ProString &s) { return seen.hasSeen(s); });
|
||||
}
|
||||
|
||||
void ProStringList::insertUnique(const ProStringList &value)
|
||||
|
@ -187,6 +187,7 @@ HEADERS += \
|
||||
qcryptographichash.h \
|
||||
qdatetime.h \
|
||||
qdatetime_p.h \
|
||||
qduplicatetracker_p.h \
|
||||
qdir.h \
|
||||
qdir_p.h \
|
||||
qdiriterator.h \
|
||||
|
@ -764,8 +764,7 @@ void QUrlQuery::removeAllQueryItems(const QString &key)
|
||||
auto firstEqualsEncodedKey = [&encodedKey](const QPair<QString, QString> &item) {
|
||||
return item.first == encodedKey;
|
||||
};
|
||||
const auto end = p->itemList.end();
|
||||
p->itemList.erase(std::remove_if(p->itemList.begin(), end, firstEqualsEncodedKey), end);
|
||||
p->itemList.removeIf(firstEqualsEncodedKey);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1252,9 +1252,7 @@ void QItemSelectionModel::select(const QItemSelection &selection, QItemSelection
|
||||
// be too late if another model observer is connected to the same modelReset slot and is invoked first
|
||||
// it might call select() on this selection model before any such QItemSelectionModelPrivate::_q_modelReset() slot
|
||||
// is invoked, so it would not be cleared yet. We clear it invalid ranges in it here.
|
||||
using namespace QtFunctionObjects;
|
||||
d->ranges.erase(std::remove_if(d->ranges.begin(), d->ranges.end(), IsNotValid()),
|
||||
d->ranges.end());
|
||||
d->ranges.removeIf(QtFunctionObjects::IsNotValid());
|
||||
|
||||
QItemSelection old = d->ranges;
|
||||
old.merge(d->currentSelection, d->currentCommand);
|
||||
@ -1755,10 +1753,7 @@ const QItemSelection QItemSelectionModel::selection() const
|
||||
selected.merge(d->currentSelection, d->currentCommand);
|
||||
// make sure we have no invalid ranges
|
||||
// ### should probably be handled more generic somewhere else
|
||||
using namespace QtFunctionObjects;
|
||||
selected.erase(std::remove_if(selected.begin(), selected.end(),
|
||||
IsNotValid()),
|
||||
selected.end());
|
||||
selected.removeIf(QtFunctionObjects::IsNotValid());
|
||||
return selected;
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,7 @@ public:
|
||||
auto isMimeTypeEqual = [&mimeType](const QMimeGlobPattern &pattern) {
|
||||
return pattern.mimeType() == mimeType;
|
||||
};
|
||||
erase(std::remove_if(begin(), end(), isMimeTypeEqual), end());
|
||||
removeIf(isMimeTypeEqual);
|
||||
}
|
||||
|
||||
void match(QMimeGlobMatchResult &result, const QString &fileName) const;
|
||||
|
@ -648,22 +648,9 @@ qsizetype QtPrivate::QStringList_lastIndexOf(const QStringList *that, const QReg
|
||||
*/
|
||||
qsizetype QtPrivate::QStringList_removeDuplicates(QStringList *that)
|
||||
{
|
||||
qsizetype n = that->size();
|
||||
qsizetype j = 0;
|
||||
|
||||
QDuplicateTracker<QString> seen;
|
||||
seen.reserve(n);
|
||||
for (qsizetype i = 0; i < n; ++i) {
|
||||
const QString &s = that->at(i);
|
||||
if (seen.hasSeen(s))
|
||||
continue;
|
||||
if (j != i)
|
||||
that->swapItemsAt(i, j);
|
||||
++j;
|
||||
}
|
||||
if (n != j)
|
||||
that->erase(that->begin() + j, that->end());
|
||||
return n - j;
|
||||
seen.reserve(that->size());
|
||||
return that->removeIf([&](const QString &s) { return seen.hasSeen(s); });
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -286,8 +286,7 @@ QStringList QCommandLineOptionPrivate::removeInvalidNames(QStringList nameList)
|
||||
if (Q_UNLIKELY(nameList.isEmpty()))
|
||||
qWarning("QCommandLineOption: Options must have at least one name");
|
||||
else
|
||||
nameList.erase(std::remove_if(nameList.begin(), nameList.end(), IsInvalidName()),
|
||||
nameList.end());
|
||||
nameList.removeIf(IsInvalidName());
|
||||
return nameList;
|
||||
}
|
||||
|
||||
|
@ -593,11 +593,8 @@ static void huntAndDestroy(QObject *needle, QDBusConnectionPrivate::ObjectTreeNo
|
||||
for (auto &node : haystack.children)
|
||||
huntAndDestroy(needle, node);
|
||||
|
||||
auto isInactive = [](QDBusConnectionPrivate::ObjectTreeNode &node) { return !node.isActive(); };
|
||||
|
||||
haystack.children.erase(std::remove_if(haystack.children.begin(), haystack.children.end(),
|
||||
isInactive),
|
||||
haystack.children.end());
|
||||
auto isInactive = [](const QDBusConnectionPrivate::ObjectTreeNode &node) { return !node.isActive(); };
|
||||
haystack.children.removeIf(isInactive);
|
||||
|
||||
if (needle == haystack.obj) {
|
||||
haystack.obj = nullptr;
|
||||
|
@ -1022,7 +1022,7 @@ QList<QByteArray> QMovie::supportedFormats()
|
||||
return !QImageReader(&buffer, format).supportsOption(QImageIOHandler::Animation);
|
||||
};
|
||||
|
||||
list.erase(std::remove_if(list.begin(), list.end(), doesntSupportAnimation), list.end());
|
||||
list.removeIf(doesntSupportAnimation);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
@ -109,12 +109,8 @@ void QSyntaxHighlighterPrivate::applyFormatChanges()
|
||||
return range.start < preeditAreaStart
|
||||
|| range.start + range.length > preeditAreaStart + preeditAreaLength;
|
||||
};
|
||||
const auto it = std::remove_if(ranges.begin(), ranges.end(),
|
||||
isOutsidePreeditArea);
|
||||
if (it != ranges.end()) {
|
||||
ranges.erase(it, ranges.end());
|
||||
if (ranges.removeIf(isOutsidePreeditArea) > 0)
|
||||
formatsChanged = true;
|
||||
}
|
||||
} else if (!ranges.isEmpty()) {
|
||||
ranges.clear();
|
||||
formatsChanged = true;
|
||||
|
@ -3756,11 +3756,7 @@ static void markFrames(QTextFrame *current, int from, int oldLength, int length)
|
||||
|
||||
QTextFrameData *fd = data(current);
|
||||
// float got removed in editing operation
|
||||
QTextFrame *null = nullptr; // work-around for (at least) MSVC 2012 emitting
|
||||
// warning C4100 for its own header <algorithm>
|
||||
// when passing nullptr directly to std::remove
|
||||
fd->floats.erase(std::remove(fd->floats.begin(), fd->floats.end(), null),
|
||||
fd->floats.end());
|
||||
fd->floats.removeAll(nullptr);
|
||||
|
||||
fd->layoutDirty = true;
|
||||
fd->sizeDirty = true;
|
||||
|
@ -106,9 +106,7 @@ void QHttpNetworkHeaderPrivate::setHeaderField(const QByteArray &name, const QBy
|
||||
auto firstEqualsName = [&name](const QPair<QByteArray, QByteArray> &header) {
|
||||
return name.compare(header.first, Qt::CaseInsensitive) == 0;
|
||||
};
|
||||
fields.erase(std::remove_if(fields.begin(), fields.end(),
|
||||
firstEqualsName),
|
||||
fields.end());
|
||||
fields.removeIf(firstEqualsName);
|
||||
fields.append(qMakePair(name, data));
|
||||
}
|
||||
|
||||
|
@ -1324,9 +1324,7 @@ void QNetworkHeadersPrivate::setRawHeaderInternal(const QByteArray &key, const Q
|
||||
auto firstEqualsKey = [&key](const RawHeaderPair &header) {
|
||||
return header.first.compare(key, Qt::CaseInsensitive) == 0;
|
||||
};
|
||||
rawHeaders.erase(std::remove_if(rawHeaders.begin(), rawHeaders.end(),
|
||||
firstEqualsKey),
|
||||
rawHeaders.end());
|
||||
rawHeaders.removeIf(firstEqualsKey);
|
||||
|
||||
if (value.isNull())
|
||||
return; // only wanted to erase key
|
||||
|
@ -493,9 +493,7 @@ void QOpenGLEngineSharedShaders::cleanupCustomStage(QOpenGLCustomShaderStage* st
|
||||
}
|
||||
return false;
|
||||
};
|
||||
cachedPrograms.erase(std::remove_if(cachedPrograms.begin(), cachedPrograms.end(),
|
||||
hasStageAsCustomShaderSouce),
|
||||
cachedPrograms.end());
|
||||
cachedPrograms.removeIf(hasStageAsCustomShaderSouce);
|
||||
}
|
||||
|
||||
|
||||
|
@ -2642,8 +2642,7 @@ QModelIndexList QAbstractItemView::selectedIndexes() const
|
||||
auto isHidden = [this](const QModelIndex &idx) {
|
||||
return isIndexHidden(idx);
|
||||
};
|
||||
const auto end = indexes.end();
|
||||
indexes.erase(std::remove_if(indexes.begin(), end, isHidden), end);
|
||||
indexes.removeIf(isHidden);
|
||||
}
|
||||
return indexes;
|
||||
}
|
||||
@ -4489,9 +4488,7 @@ QModelIndexList QAbstractItemViewPrivate::selectedDraggableIndexes() const
|
||||
auto isNotDragEnabled = [this](const QModelIndex &index) {
|
||||
return !isIndexDragEnabled(index);
|
||||
};
|
||||
indexes.erase(std::remove_if(indexes.begin(), indexes.end(),
|
||||
isNotDragEnabled),
|
||||
indexes.end());
|
||||
indexes.removeIf(isNotDragEnabled);
|
||||
return indexes;
|
||||
}
|
||||
|
||||
|
@ -1522,8 +1522,7 @@ QModelIndexList QListView::selectedIndexes() const
|
||||
auto ignorable = [this, d](const QModelIndex &index) {
|
||||
return index.column() != d->column || index.parent() != d->root || isIndexHidden(index);
|
||||
};
|
||||
viewSelected.erase(std::remove_if(viewSelected.begin(), viewSelected.end(), ignorable),
|
||||
viewSelected.end());
|
||||
viewSelected.removeIf(ignorable);
|
||||
return viewSelected;
|
||||
}
|
||||
|
||||
@ -1960,9 +1959,7 @@ void QListViewPrivate::removeCurrentAndDisabled(QList<QModelIndex> *indexes,
|
||||
auto isCurrentOrDisabled = [this, current](const QModelIndex &index) {
|
||||
return !isIndexEnabled(index) || index == current;
|
||||
};
|
||||
indexes->erase(std::remove_if(indexes->begin(), indexes->end(),
|
||||
isCurrentOrDisabled),
|
||||
indexes->end());
|
||||
indexes->removeIf(isCurrentOrDisabled);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -173,7 +173,7 @@ bool QWindowsStyle::eventFilter(QObject *o, QEvent *e)
|
||||
return w->isWindow() || !w->isVisible()
|
||||
|| w->style()->styleHint(SH_UnderlineShortcut, nullptr, w);
|
||||
};
|
||||
l.erase(std::remove_if(l.begin(), l.end(), ignorable), l.end());
|
||||
l.removeIf(ignorable);
|
||||
// Update states before repainting
|
||||
d->seenAlt.append(widget);
|
||||
d->alt_down = true;
|
||||
|
@ -199,9 +199,7 @@ QList<QAbstractButton *>QAbstractButtonPrivate::queryButtonList() const
|
||||
#endif
|
||||
;
|
||||
};
|
||||
candidates.erase(std::remove_if(candidates.begin(), candidates.end(),
|
||||
isNoMemberOfMyAutoExclusiveGroup),
|
||||
candidates.end());
|
||||
candidates.removeIf(isNoMemberOfMyAutoExclusiveGroup);
|
||||
}
|
||||
return candidates;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user