summaryrefslogtreecommitdiffstats
path: root/src/network/access/qnetworkdiskcache.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/access/qnetworkdiskcache.cpp')
-rw-r--r--src/network/access/qnetworkdiskcache.cpp67
1 files changed, 32 insertions, 35 deletions
diff --git a/src/network/access/qnetworkdiskcache.cpp b/src/network/access/qnetworkdiskcache.cpp
index 1d87d63f5d..99e67cb463 100644
--- a/src/network/access/qnetworkdiskcache.cpp
+++ b/src/network/access/qnetworkdiskcache.cpp
@@ -1,31 +1,37 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtNetwork module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -108,11 +114,7 @@ QNetworkDiskCache::QNetworkDiskCache(QObject *parent)
QNetworkDiskCache::~QNetworkDiskCache()
{
Q_D(QNetworkDiskCache);
- QHashIterator<QIODevice*, QCacheItem*> it(d->inserting);
- while (it.hasNext()) {
- it.next();
- delete it.value();
- }
+ qDeleteAll(d->inserting);
}
/*!
@@ -158,7 +160,7 @@ void QNetworkDiskCache::setCacheDirectory(const QString &cacheDir)
qint64 QNetworkDiskCache::cacheSize() const
{
#if defined(QNETWORKDISKCACHE_DEBUG)
- qDebug() << "QNetworkDiskCache::cacheSize()";
+ qDebug("QNetworkDiskCache::cacheSize()");
#endif
Q_D(const QNetworkDiskCache);
if (d->cacheDirectory.isEmpty())
@@ -183,7 +185,7 @@ QIODevice *QNetworkDiskCache::prepare(const QNetworkCacheMetaData &metaData)
return 0;
if (d->cacheDirectory.isEmpty()) {
- qWarning() << "QNetworkDiskCache::prepare() The cache directory is not set";
+ qWarning("QNetworkDiskCache::prepare() The cache directory is not set");
return 0;
}
@@ -210,7 +212,7 @@ QIODevice *QNetworkDiskCache::prepare(const QNetworkCacheMetaData &metaData)
cacheItem->file = 0;
}
if (!cacheItem->file || !cacheItem->file->open()) {
- qWarning() << "QNetworkDiskCache::prepare() unable to open temporary file";
+ qWarning("QNetworkDiskCache::prepare() unable to open temporary file");
cacheItem.reset();
return 0;
}
@@ -230,8 +232,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;
}
@@ -313,13 +315,11 @@ bool QNetworkDiskCache::remove(const QUrl &url)
Q_D(QNetworkDiskCache);
// remove is also used to cancel insertions, not a common operation
- QHashIterator<QIODevice*, QCacheItem*> it(d->inserting);
- while (it.hasNext()) {
- it.next();
+ for (auto it = d->inserting.cbegin(), end = d->inserting.cend(); it != end; ++it) {
QCacheItem *item = it.value();
if (item && item->metaData.url() == url) {
delete item;
- d->inserting.remove(it.key());
+ d->inserting.erase(it);
return true;
}
}
@@ -448,7 +448,7 @@ void QNetworkDiskCache::updateMetaData(const QNetworkCacheMetaData &metaData)
QIODevice *oldDevice = data(url);
if (!oldDevice) {
#if defined(QNETWORKDISKCACHE_DEBUG)
- qDebug() << "QNetworkDiskCache::updateMetaData(), no device!";
+ qDebug("QNetworkDiskCache::updateMetaData(), no device!");
#endif
return;
}
@@ -521,7 +521,7 @@ qint64 QNetworkDiskCache::expire()
return d->currentCacheSize;
if (cacheDirectory().isEmpty()) {
- qWarning() << "QNetworkDiskCache::expire() The cache directory is not set";
+ qWarning("QNetworkDiskCache::expire() The cache directory is not set");
return 0;
}
@@ -553,10 +553,7 @@ qint64 QNetworkDiskCache::expire()
QFile file(name);
if (name.contains(PREPARED_SLASH)) {
- QHashIterator<QIODevice*, QCacheItem*> iterator(d->inserting);
- while (iterator.hasNext()) {
- iterator.next();
- QCacheItem *item = iterator.value();
+ for (QCacheItem *item : qAsConst(d->inserting)) {
if (item && item->file && item->file->fileName() == name) {
delete item->file;
item->file = 0;
@@ -587,7 +584,7 @@ qint64 QNetworkDiskCache::expire()
void QNetworkDiskCache::clear()
{
#if defined(QNETWORKDISKCACHE_DEBUG)
- qDebug() << "QNetworkDiskCache::clear()";
+ qDebug("QNetworkDiskCache::clear()");
#endif
Q_D(QNetworkDiskCache);
qint64 size = d->maximumCacheSize;