Ignore:
Timestamp:
Aug 3, 2010, 3:18:00 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

network: Improve network disk cache performance by reducing the number of stat() calls twice when expiring the cache items [based on patch by rudi].

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/network/access/qnetworkdiskcache.cpp

    r769 r774  
    512512    QDirIterator it(cacheDirectory(), filters, QDirIterator::Subdirectories);
    513513
    514     QMultiMap<QDateTime, QString> cacheItems;
     514    // performance tweak: we store the size together with the name in
     515    // order to avoid querying the size again before the file is deleted
     516    typedef QPair<QString, qint64> ExpireInfo;
     517
     518    QMultiMap<QDateTime, ExpireInfo> cacheItems;
    515519    qint64 totalSize = 0;
    516520    while (it.hasNext()) {
     
    519523        QString fileName = info.fileName();
    520524        if (fileName.endsWith(CACHE_POSTFIX) && fileName.startsWith(CACHE_PREFIX)) {
    521             cacheItems.insert(info.created(), path);
    522             totalSize += info.size();
     525            ExpireInfo item = qMakePair(path, info.size());
     526            cacheItems.insert(info.created(), item);
     527            totalSize += item.second;
    523528        }
    524529    }
     
    526531    int removedFiles = 0;
    527532    qint64 goal = (maximumCacheSize() * 9) / 10;
    528     QMultiMap<QDateTime, QString>::const_iterator i = cacheItems.constBegin();
     533    QMultiMap<QDateTime, >::const_iterator i = cacheItems.constBegin();
    529534    while (i != cacheItems.constEnd()) {
    530535        if (totalSize < goal)
    531536            break;
    532         QString name = i.value();
    533         QFile file(name);
    534         qint64 size = file.size();
    535         file.remove();
    536         totalSize -= size;
     537        const ExpireInfo &item = i.value();
     538        QFile::remove(item.first);
     539        totalSize -= item.second;
    537540        ++removedFiles;
    538541        ++i;
Note: See TracChangeset for help on using the changeset viewer.