diff --git a/src/core/kcoredirlister.cpp b/src/core/kcoredirlister.cpp --- a/src/core/kcoredirlister.cpp +++ b/src/core/kcoredirlister.cpp @@ -272,7 +272,7 @@ // List existing items in a delayed manner, just like things would happen // if we were not using the cache. - qCDebug(KIO_CORE_DIRLISTER) << "Listing" << itemU->lstItems.count() << "cached items soon"; + qCDebug(KIO_CORE_DIRLISTER) << "Listing" << itemU->hashItems.count() << "cached items soon"; KCoreDirLister::Private::CachedItemsJob* cachedItemsJob = new KCoreDirLister::Private::CachedItemsJob(lister, _url, _reload); if (job) { // The ListJob will take care of emitting completed. @@ -344,7 +344,7 @@ if (!itemU) { qCWarning(KIO_CORE) << "Can't find item for directory" << urlStr << "anymore"; } else { - const QList items = itemU->lstItems; + const QHash items = itemU->hashItems; const KFileItem rootItem = itemU->rootItem; _reload = _reload || !itemU->complete; @@ -621,8 +621,8 @@ // Look for a manually-mounted directory inside // If there's one, we can't keep a watch either, FAM would prevent unmounting the CDROM // I hope this isn't too slow - QList::const_iterator kit = item->lstItems.constBegin(); - QList::const_iterator kend = item->lstItems.constEnd(); + auto kit = item->hashItems.constBegin(); + auto kend = item->hashItems.constEnd(); for (; kit != kend && !containsManuallyMounted; ++kit) if ((*kit).isDir() && manually_mounted((*kit).url().toLocalFile(), possibleMountPoints)) { containsManuallyMounted = true; @@ -783,10 +783,10 @@ return item; } -QList *KCoreDirListerCache::itemsForDir(const QUrl &dir) const +QHash *KCoreDirListerCache::itemsForDir(const QUrl &dir) const { DirItem *item = dirItemForUrl(dir); - return item ? &item->lstItems : nullptr; + return item ? &item->hashItems : nullptr; } KFileItem KCoreDirListerCache::findByName(const KCoreDirLister *lister, const QString &_name) const @@ -798,8 +798,8 @@ DirItem *dirItem = itemsInUse.value((*it).toString()); Q_ASSERT(dirItem); - auto lit = dirItem->lstItems.constBegin(); - const auto litend = dirItem->lstItems.constEnd(); + auto lit = dirItem->hashItems.constBegin(); + const auto litend = dirItem->hashItems.constEnd(); for (; lit != litend; ++lit) { if ((*lit).name() == _name) { return *lit; @@ -822,13 +822,11 @@ if (dirItem) { // If lister is set, check that it contains this dir if (!lister || lister->d->lstDirs.contains(parentDir)) { - auto it = dirItem->lstItems.begin(); - const auto end = dirItem->lstItems.end(); - for (; it != end; ++it) { - if ((*it).url() == url) { - *it = itemToCopy; - return; - } + auto it = dirItem->hashItems.find(url); + if (it != dirItem->hashItems.end()) + { + dirItem->hashItems.erase(it); + dirItem->hashItems.insert(itemToCopy.url(), itemToCopy); } } } @@ -846,16 +844,14 @@ if (dirItem) { // If lister is set, check that it contains this dir if (!lister || lister->d->lstDirs.contains(parentDir)) { - QList::iterator it = dirItem->lstItems.begin(); - const QList::iterator end = dirItem->lstItems.end(); - for (; it != end; ++it) { - if ((*it).url() == url) { - KFileItem retKFileItem = *it; - if (refresh) { - (*it).refresh(); - } - return retKFileItem; + auto it = dirItem->hashItems.find(url); + if (it != dirItem->hashItems.end()) + { + KFileItem retKFileItem = *it; + if (refresh) { + (*it).refresh(); } + return retKFileItem; } } } @@ -918,17 +914,18 @@ if (!dirItem) { continue; } - for (QList::iterator fit = dirItem->lstItems.begin(), fend = dirItem->lstItems.end(); fit != fend; ++fit) { - if ((*fit).url() == url) { + + auto fit = dirItem->hashItems.find(url); + if (fit != dirItem->hashItems.end()) + { const KFileItem fileitem = *fit; removedItemsByDir[parentDir.toString()].append(fileitem); // If we found a fileitem, we can test if it's a dir. If not, we'll go to deleteDir just in case. if (fileitem.isNull() || fileitem.isDir()) { deletedSubdirs.append(url); } - dirItem->lstItems.erase(fit); // remove fileitem from list + dirItem->hashItems.erase(fit); // remove fileitem from list break; - } } } @@ -1304,7 +1301,7 @@ } qCDebug(KIO_CORE_DIRLISTER)<< "Adding item: " << item.url(); - dir->lstItems.append(item); + dir->hashItems.insert(item.url(), item); foreach (KCoreDirLister *kdl, dirData.listersCurrentlyListing) { kdl->d->addNewItem(url, item); @@ -1533,7 +1530,7 @@ kdl->d->rootFileItem = newDir->rootItem; } - kdl->d->addNewItems(newUrl, newDir->lstItems); + kdl->d->addNewItems(newUrl, newDir->hashItems); kdl->d->emitItems(); } } else if ((newDir = itemsCached.take(newUrlStr))) { @@ -1551,14 +1548,14 @@ kdl->d->rootFileItem = newDir->rootItem; } - kdl->d->addNewItems(newUrl, newDir->lstItems); + kdl->d->addNewItems(newUrl, newDir->hashItems); kdl->d->emitItems(); } } else { qCDebug(KIO_CORE_DIRLISTER) << newUrl << "has not been listed yet."; dir->rootItem = KFileItem(); - dir->lstItems.clear(); + dir->hashItems.clear(); dir->redirect(newUrl); itemsInUse.insert(newUrlStr, dir); KCoreDirListerCacheDirectoryData &newDirData = directoryData[newUrlStr]; @@ -1635,7 +1632,7 @@ dir)); // Rename all items under that dir - for (QList::iterator kit = dir->lstItems.begin(), kend = dir->lstItems.end(); + for (auto kit = dir->hashItems.begin(), kend = dir->hashItems.end(); kit != kend; ++kit) { const KFileItem oldItem = *kit; @@ -1814,7 +1811,7 @@ // Fill the hash from the old list of items. We'll remove entries as we see them // in the new listing, and the resulting hash entries will be the deleted items. - for (QList::iterator kit = dir->lstItems.begin(), kend = dir->lstItems.end(); kit != kend; ++kit) { + for (auto kit = dir->hashItems.begin(), kend = dir->hashItems.end(); kit != kend; ++kit) { fileItems.insert((*kit).name(), *kit); } @@ -1890,8 +1887,7 @@ fileItems.erase(fiit); } else { // this is a new file qCDebug(KIO_CORE_DIRLISTER) << "new file:" << name; - - dir->lstItems.append(item); + dir->hashItems.insert(item.url(), item); foreach (KCoreDirLister *kdl, listers) { kdl->d->addNewItem(jobUrl, item); @@ -1902,7 +1898,7 @@ runningListJobs.remove(job); if (!fileItems.isEmpty()) { - deleteUnmarkedItems(listers, dir->lstItems, fileItems); + deleteUnmarkedItems(listers, dir->hashItems, fileItems); } foreach (KCoreDirLister *kdl, listers) { @@ -1959,7 +1955,7 @@ job->kill(); } -void KCoreDirListerCache::deleteUnmarkedItems(const QList &listers, QList &lstItems, const QHash &itemsToDelete) +void KCoreDirListerCache::deleteUnmarkedItems(const QList &listers, QHash &hashItems, const QHash &itemsToDelete) { // Make list of deleted items (for emitting) KFileItemList deletedItems; @@ -1971,9 +1967,9 @@ } // Delete all remaining items - QMutableListIterator it(lstItems); + QMutableHashIterator it(hashItems); while (it.hasNext()) { - if (itemsToDelete.contains(it.next().name())) { + if (itemsToDelete.contains(it.next().value().name())) { it.remove(); } } @@ -2104,7 +2100,7 @@ << "rootItem:" << (!itu.value()->rootItem.isNull() ? itu.value()->rootItem.url() : QUrl()) << "autoUpdates refcount:" << itu.value()->autoUpdates << "complete:" << itu.value()->complete - << QStringLiteral("with %1 items.").arg(itu.value()->lstItems.count()); + << QStringLiteral("with %1 items.").arg(itu.value()->hashItems.count()); } QList listersWithoutJob; @@ -2145,7 +2141,7 @@ DirItem *dirItem = itemsCached.object(cachedDir); qCDebug(KIO_CORE_DIRLISTER) << " " << cachedDir << "rootItem:" << (!dirItem->rootItem.isNull() ? dirItem->rootItem.url().toString() : QStringLiteral("NULL")) - << "with" << dirItem->lstItems.count() << "items."; + << "with" << dirItem->hashItems.count() << "items."; } // Abort on listers without jobs -after- showing the full dump. Easier debugging. @@ -2279,7 +2275,7 @@ // Fill hash with all items that are currently visible QSet oldVisibleItems; Q_FOREACH (const QUrl &dir, lstDirs) { - QList *itemList = kDirListerCache()->itemsForDir(dir); + QHash *itemList = kDirListerCache()->itemsForDir(dir); if (!itemList) { continue; } @@ -2296,7 +2292,7 @@ Q_FOREACH (const QUrl &dir, lstDirs) { KFileItemList deletedItems; - QList *itemList = kDirListerCache()->itemsForDir(dir); + QHash *itemList = kDirListerCache()->itemsForDir(dir); if (!itemList) { continue; } @@ -2529,13 +2525,12 @@ } } -void KCoreDirLister::Private::addNewItems(const QUrl &directoryUrl, const QList &items) -{ +void KCoreDirLister::Private::addNewItems(const QUrl &directoryUrl, const QHash &items){ // TODO: make this faster - test if we have a filter at all first // DF: was this profiled? The matchesFoo() functions should be fast, w/o filters... // Of course if there is no filter and we can do a range-insertion instead of a loop, that might be good. - QList::const_iterator kit = items.begin(); - const QList::const_iterator kend = items.end(); + auto kit = items.begin(); + const auto kend = items.end(); for (; kit != kend; ++kit) { addNewItem(directoryUrl, *kit); } @@ -2741,7 +2736,7 @@ KFileItemList KCoreDirLister::itemsForDir(const QUrl &dir, WhichItems which) const { - QList *allItems = kDirListerCache()->itemsForDir(dir); + QHash *allItems = kDirListerCache()->itemsForDir(dir); KFileItemList result; if (!allItems) { return result; @@ -2755,8 +2750,8 @@ } } else { // only items passing the filters - QList::const_iterator kit = allItems->constBegin(); - const QList::const_iterator kend = allItems->constEnd(); + QHash::const_iterator kit = allItems->constBegin(); + const QHash::const_iterator kend = allItems->constEnd(); for (; kit != kend; ++kit) { const KFileItem &item = *kit; if (d->isItemVisible(item) && matchesMimeFilter(item)) { diff --git a/src/core/kcoredirlister_p.h b/src/core/kcoredirlister_p.h --- a/src/core/kcoredirlister_p.h +++ b/src/core/kcoredirlister_p.h @@ -72,7 +72,7 @@ void jobDone(KIO::ListJob *); uint numJobs(); void addNewItem(const QUrl &directoryUrl, const KFileItem &item); - void addNewItems(const QUrl &directoryUrl, const QList &items); + void addNewItems(const QUrl &directoryUrl, const QHash &items); void addRefreshItem(const QUrl &directoryUrl, const KFileItem &oldItem, const KFileItem &item); void emitItems(); void emitItemsDeleted(const KFileItemList &items); @@ -177,7 +177,7 @@ void updateDirectory(const QUrl &dir); KFileItem itemForUrl(const QUrl &url); - QList *itemsForDir(const QUrl &dir) const; + QHash *itemsForDir(const QUrl &dir) const; bool listDir(KCoreDirLister *lister, const QUrl &_url, bool _keep, bool _reload); @@ -276,7 +276,7 @@ // when there were items deleted from the filesystem all the listers holding // the parent directory need to be notified, the items have to be deleted // and removed from the cache including all the children. - void deleteUnmarkedItems(const QList&, QList &lstItems, const QHash &itemsToDelete); + void deleteUnmarkedItems(const QList&, QHash &hashItems, const QHash &itemsToDelete); // Helper method called when we know that a list of items was deleted void itemsDeleted(const QList &listers, const KFileItemList &deletedItems); @@ -341,7 +341,7 @@ sendSignal(false, url); } } - lstItems.clear(); + hashItems.clear(); } void sendSignal(bool entering, const QUrl &url) @@ -421,7 +421,7 @@ // the list, so they give no root item KFileItem rootItem; - QList lstItems; + QHash hashItems; }; // definition of the cache of ".hidden" files