QtBase: avoid uses of Java-style iterators [QHash, QMap]
Java-style iterators are slower than STL-style ones, so they should not be used in library code. Replaced them with C++11 range-for, STL iterators or, in one case, qDeleteAll(). In one case, avoid a double hash lookup by using erase(it) instead of remove(it.key()), which we can now do without detaching, due to the new erase() taking const_iterator. Change-Id: I96174657fed70f76120b2c9d8190b4e70d5d8179 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
This commit is contained in:
parent
1d3503b8f3
commit
fdfd63053a
@ -685,9 +685,7 @@ void VcprojGenerator::writeSubDirs(QTextStream &t)
|
|||||||
|
|
||||||
t << _slnGlobalBeg;
|
t << _slnGlobalBeg;
|
||||||
|
|
||||||
QHashIterator<VcsolutionDepend *, QStringList> extraIt(extraSubdirs);
|
for (auto extraIt = extraSubdirs.cbegin(), end = extraSubdirs.cend(); extraIt != end; ++extraIt) {
|
||||||
while (extraIt.hasNext()) {
|
|
||||||
extraIt.next();
|
|
||||||
for (const QString &depend : extraIt.value()) {
|
for (const QString &depend : extraIt.value()) {
|
||||||
if (!projGuids[depend].isEmpty()) {
|
if (!projGuids[depend].isEmpty()) {
|
||||||
extraIt.key()->dependencies << projGuids[depend];
|
extraIt.key()->dependencies << projGuids[depend];
|
||||||
|
@ -114,11 +114,7 @@ QNetworkDiskCache::QNetworkDiskCache(QObject *parent)
|
|||||||
QNetworkDiskCache::~QNetworkDiskCache()
|
QNetworkDiskCache::~QNetworkDiskCache()
|
||||||
{
|
{
|
||||||
Q_D(QNetworkDiskCache);
|
Q_D(QNetworkDiskCache);
|
||||||
QHashIterator<QIODevice*, QCacheItem*> it(d->inserting);
|
qDeleteAll(d->inserting);
|
||||||
while (it.hasNext()) {
|
|
||||||
it.next();
|
|
||||||
delete it.value();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -319,13 +315,11 @@ bool QNetworkDiskCache::remove(const QUrl &url)
|
|||||||
Q_D(QNetworkDiskCache);
|
Q_D(QNetworkDiskCache);
|
||||||
|
|
||||||
// remove is also used to cancel insertions, not a common operation
|
// remove is also used to cancel insertions, not a common operation
|
||||||
QHashIterator<QIODevice*, QCacheItem*> it(d->inserting);
|
for (auto it = d->inserting.cbegin(), end = d->inserting.cend(); it != end; ++it) {
|
||||||
while (it.hasNext()) {
|
|
||||||
it.next();
|
|
||||||
QCacheItem *item = it.value();
|
QCacheItem *item = it.value();
|
||||||
if (item && item->metaData.url() == url) {
|
if (item && item->metaData.url() == url) {
|
||||||
delete item;
|
delete item;
|
||||||
d->inserting.remove(it.key());
|
d->inserting.erase(it);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -559,10 +553,7 @@ qint64 QNetworkDiskCache::expire()
|
|||||||
QFile file(name);
|
QFile file(name);
|
||||||
|
|
||||||
if (name.contains(PREPARED_SLASH)) {
|
if (name.contains(PREPARED_SLASH)) {
|
||||||
QHashIterator<QIODevice*, QCacheItem*> iterator(d->inserting);
|
for (QCacheItem *item : qAsConst(d->inserting)) {
|
||||||
while (iterator.hasNext()) {
|
|
||||||
iterator.next();
|
|
||||||
QCacheItem *item = iterator.value();
|
|
||||||
if (item && item->file && item->file->fileName() == name) {
|
if (item && item->file && item->file->fileName() == name) {
|
||||||
delete item->file;
|
delete item->file;
|
||||||
item->file = 0;
|
item->file = 0;
|
||||||
|
@ -793,11 +793,8 @@ void QColumnView::initializeColumn(QAbstractItemView *column) const
|
|||||||
column->setModel(model());
|
column->setModel(model());
|
||||||
|
|
||||||
// Copy the custom delegate per row
|
// Copy the custom delegate per row
|
||||||
QMapIterator<int, QPointer<QAbstractItemDelegate> > i(d->rowDelegates);
|
for (auto i = d->rowDelegates.cbegin(), end = d->rowDelegates.cend(); i != end; ++i)
|
||||||
while (i.hasNext()) {
|
|
||||||
i.next();
|
|
||||||
column->setItemDelegateForRow(i.key(), i.value());
|
column->setItemDelegateForRow(i.key(), i.value());
|
||||||
}
|
|
||||||
|
|
||||||
// set the delegate to be the columnview delegate
|
// set the delegate to be the columnview delegate
|
||||||
QAbstractItemDelegate *delegate = column->itemDelegate();
|
QAbstractItemDelegate *delegate = column->itemDelegate();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user