summaryrefslogtreecommitdiffstats
path: root/src/network/access
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2021-07-10 08:17:06 +0200
committerMarc Mutz <marc.mutz@kdab.com>2021-07-14 20:05:41 +0200
commit41a5480cc78f9ba04be50c2481172ef86ca64079 (patch)
treedc6f24ebaeb292a6ceb2c9346d9193a5581c1fa5 /src/network/access
parent6c1bc7798bec6bc48439b297e55d14a9da0a3673 (diff)
Hold QRingBuffer and QNonContiguousByteDevice in shared_ptr
... instead of QSharedPointer. QSharedPointer performs twice as many atomic operations per pointer copy as std::shared_ptr, and this is private API, we're not bound by BC constraints, so we can port to the more efficient version. Change-Id: I9572a8321aae381e5dbe4a51119f2c9494a8fbc7 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/network/access')
-rw-r--r--src/network/access/qnetworkaccessbackend.cpp6
-rw-r--r--src/network/access/qnetworkreplyhttpimpl.cpp14
-rw-r--r--src/network/access/qnetworkreplyhttpimpl_p.h6
-rw-r--r--src/network/access/qnetworkreplyimpl.cpp4
-rw-r--r--src/network/access/qnetworkreplyimpl_p.h4
-rw-r--r--src/network/access/qnetworkreplywasmimpl.cpp2
-rw-r--r--src/network/access/qnetworkreplywasmimpl_p.h4
7 files changed, 23 insertions, 17 deletions
diff --git a/src/network/access/qnetworkaccessbackend.cpp b/src/network/access/qnetworkaccessbackend.cpp
index f7e29340d9..2284461099 100644
--- a/src/network/access/qnetworkaccessbackend.cpp
+++ b/src/network/access/qnetworkaccessbackend.cpp
@@ -80,7 +80,7 @@ public:
QNetworkAccessBackend::TargetTypes m_targetTypes;
QNetworkAccessBackend::SecurityFeatures m_securityFeatures;
QNetworkAccessBackend::IOFeatures m_ioFeatures;
- QSharedPointer<QNonContiguousByteDevice> uploadByteDevice;
+ std::shared_ptr<QNonContiguousByteDevice> uploadByteDevice;
QIODevice *wrappedUploadByteDevice;
QNetworkReplyImplPrivate *m_reply = nullptr;
QNetworkAccessManagerPrivate *m_manager = nullptr;
@@ -566,7 +566,7 @@ QIODevice *QNetworkAccessBackend::createUploadByteDevice()
// We want signal emissions only for normal asynchronous uploads
if (!isSynchronous()) {
- connect(d->uploadByteDevice.data(), &QNonContiguousByteDevice::readProgress, this,
+ connect(d->uploadByteDevice.get(), &QNonContiguousByteDevice::readProgress, this,
[this](qint64 a, qint64 b) {
Q_D(QNetworkAccessBackend);
if (!d->m_reply->isFinished)
@@ -574,7 +574,7 @@ QIODevice *QNetworkAccessBackend::createUploadByteDevice()
});
}
- d->wrappedUploadByteDevice = QNonContiguousByteDeviceFactory::wrap(d->uploadByteDevice.data());
+ d->wrappedUploadByteDevice = QNonContiguousByteDeviceFactory::wrap(d->uploadByteDevice.get());
return d->wrappedUploadByteDevice;
}
diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp
index b68e82a5e1..e43b9dcb67 100644
--- a/src/network/access/qnetworkreplyhttpimpl.cpp
+++ b/src/network/access/qnetworkreplyhttpimpl.cpp
@@ -199,7 +199,7 @@ QNetworkReplyHttpImpl::QNetworkReplyHttpImpl(QNetworkAccessManager* const manage
if (d->synchronous && outgoingData) {
// The synchronous HTTP is a corner case, we will put all upload data in one big QByteArray in the outgoingDataBuffer.
// Yes, this is not the most efficient thing to do, but on the other hand synchronous XHR needs to die anyway.
- d->outgoingDataBuffer = QSharedPointer<QRingBuffer>::create();
+ d->outgoingDataBuffer = std::make_shared<QRingBuffer>();
qint64 previousDataSize = 0;
do {
previousDataSize = d->outgoingDataBuffer->size();
@@ -923,14 +923,14 @@ void QNetworkReplyHttpImplPrivate::postRequest(const QNetworkRequest &newHttpReq
delegate->httpRequest.setUploadByteDevice(forwardUploadDevice);
// If the device in the user thread claims it has more data, keep the flow to HTTP thread going
- QObject::connect(uploadByteDevice.data(), SIGNAL(readyRead()),
+ QObject::connect(uploadByteDevice.get(), SIGNAL(readyRead()),
q, SLOT(uploadByteDeviceReadyReadSlot()),
Qt::QueuedConnection);
// From user thread to http thread:
QObject::connect(q, SIGNAL(haveUploadData(qint64,QByteArray,bool,qint64)),
forwardUploadDevice, SLOT(haveDataSlot(qint64,QByteArray,bool,qint64)), Qt::QueuedConnection);
- QObject::connect(uploadByteDevice.data(), SIGNAL(readyRead()),
+ QObject::connect(uploadByteDevice.get(), SIGNAL(readyRead()),
forwardUploadDevice, SIGNAL(readyRead()),
Qt::QueuedConnection);
@@ -953,7 +953,7 @@ void QNetworkReplyHttpImplPrivate::postRequest(const QNetworkRequest &newHttpReq
// use the uploadByteDevice provided to us by the QNetworkReplyImpl.
// The code that is in start() makes sure it is safe to use from a thread
// since it only wraps a QRingBuffer
- delegate->httpRequest.setUploadByteDevice(uploadByteDevice.data());
+ delegate->httpRequest.setUploadByteDevice(uploadByteDevice.get());
}
}
@@ -1966,7 +1966,7 @@ void QNetworkReplyHttpImplPrivate::_q_bufferOutgoingData()
if (!outgoingDataBuffer) {
// first call, create our buffer
- outgoingDataBuffer = QSharedPointer<QRingBuffer>::create();
+ outgoingDataBuffer = std::make_shared<QRingBuffer>();
QObject::connect(outgoingData, SIGNAL(readyRead()), q, SLOT(_q_bufferOutgoingData()));
QObject::connect(outgoingData, SIGNAL(readChannelFinished()), q, SLOT(_q_bufferOutgoingDataFinished()));
@@ -2066,10 +2066,10 @@ QNonContiguousByteDevice* QNetworkReplyHttpImplPrivate::createUploadByteDevice()
// We want signal emissions only for normal asynchronous uploads
if (!synchronous)
- QObject::connect(uploadByteDevice.data(), SIGNAL(readProgress(qint64,qint64)),
+ QObject::connect(uploadByteDevice.get(), SIGNAL(readProgress(qint64,qint64)),
q, SLOT(emitReplyUploadProgress(qint64,qint64)));
- return uploadByteDevice.data();
+ return uploadByteDevice.get();
}
void QNetworkReplyHttpImplPrivate::_q_finished()
diff --git a/src/network/access/qnetworkreplyhttpimpl_p.h b/src/network/access/qnetworkreplyhttpimpl_p.h
index 12fc484fe5..8fb59cdd49 100644
--- a/src/network/access/qnetworkreplyhttpimpl_p.h
+++ b/src/network/access/qnetworkreplyhttpimpl_p.h
@@ -75,6 +75,8 @@ Q_MOC_INCLUDE(<QtNetwork/QAuthenticator>)
#include <private/qdecompresshelper_p.h>
+#include <memory>
+
QT_REQUIRE_CONFIG(http);
QT_BEGIN_NAMESPACE
@@ -197,11 +199,11 @@ public:
// upload
QNonContiguousByteDevice* createUploadByteDevice();
- QSharedPointer<QNonContiguousByteDevice> uploadByteDevice;
+ std::shared_ptr<QNonContiguousByteDevice> uploadByteDevice;
qint64 uploadByteDevicePosition;
bool uploadDeviceChoking; // if we couldn't readPointer() any data at the moment
QIODevice *outgoingData;
- QSharedPointer<QRingBuffer> outgoingDataBuffer;
+ std::shared_ptr<QRingBuffer> outgoingDataBuffer;
void emitReplyUploadProgress(qint64 bytesSent, qint64 bytesTotal); // dup?
void onRedirected(const QUrl &redirectUrl, int httpStatus, int maxRedirectsRemainig);
void followRedirect();
diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp
index 61745155f5..39729dd13a 100644
--- a/src/network/access/qnetworkreplyimpl.cpp
+++ b/src/network/access/qnetworkreplyimpl.cpp
@@ -193,7 +193,7 @@ void QNetworkReplyImplPrivate::_q_bufferOutgoingData()
if (!outgoingDataBuffer) {
// first call, create our buffer
- outgoingDataBuffer = QSharedPointer<QRingBuffer>::create();
+ outgoingDataBuffer = std::make_shared<QRingBuffer>();
QObject::connect(outgoingData, SIGNAL(readyRead()), q, SLOT(_q_bufferOutgoingData()));
QObject::connect(outgoingData, SIGNAL(readChannelFinished()), q, SLOT(_q_bufferOutgoingDataFinished()));
@@ -249,7 +249,7 @@ void QNetworkReplyImplPrivate::setup(QNetworkAccessManager::Operation op, const
// The synchronous HTTP is a corner case, we will put all upload data in one big QByteArray in the outgoingDataBuffer.
// Yes, this is not the most efficient thing to do, but on the other hand synchronous XHR needs to die anyway.
if (synchronousHttpAttribute.toBool() && outgoingData) {
- outgoingDataBuffer = QSharedPointer<QRingBuffer>::create();
+ outgoingDataBuffer = std::make_shared<QRingBuffer>();
qint64 previousDataSize = 0;
do {
previousDataSize = outgoingDataBuffer->size();
diff --git a/src/network/access/qnetworkreplyimpl_p.h b/src/network/access/qnetworkreplyimpl_p.h
index 7d014f9173..e390acb69d 100644
--- a/src/network/access/qnetworkreplyimpl_p.h
+++ b/src/network/access/qnetworkreplyimpl_p.h
@@ -63,6 +63,8 @@
#include "private/qbytedata_p.h"
#include <QSharedPointer>
+#include <memory>
+
QT_BEGIN_NAMESPACE
class QAbstractNetworkCache;
@@ -153,7 +155,7 @@ public:
QNetworkAccessBackend *backend;
QIODevice *outgoingData;
- QSharedPointer<QRingBuffer> outgoingDataBuffer;
+ std::shared_ptr<QRingBuffer> outgoingDataBuffer;
QIODevice *copyDevice;
QAbstractNetworkCache *networkCache() const;
diff --git a/src/network/access/qnetworkreplywasmimpl.cpp b/src/network/access/qnetworkreplywasmimpl.cpp
index 2cae6847b8..bbb41da9fb 100644
--- a/src/network/access/qnetworkreplywasmimpl.cpp
+++ b/src/network/access/qnetworkreplywasmimpl.cpp
@@ -406,7 +406,7 @@ void QNetworkReplyWasmImplPrivate::_q_bufferOutgoingData()
if (!outgoingDataBuffer) {
// first call, create our buffer
- outgoingDataBuffer = QSharedPointer<QRingBuffer>::create();
+ outgoingDataBuffer = std::make_shared<QRingBuffer>();
QObject::connect(outgoingData, SIGNAL(readyRead()), q, SLOT(_q_bufferOutgoingData()));
QObject::connect(outgoingData, SIGNAL(readChannelFinished()), q, SLOT(_q_bufferOutgoingDataFinished()));
diff --git a/src/network/access/qnetworkreplywasmimpl_p.h b/src/network/access/qnetworkreplywasmimpl_p.h
index db9fd5657e..407890d837 100644
--- a/src/network/access/qnetworkreplywasmimpl_p.h
+++ b/src/network/access/qnetworkreplywasmimpl_p.h
@@ -63,6 +63,8 @@
#include <emscripten.h>
#include <emscripten/fetch.h>
+#include <memory>
+
QT_BEGIN_NAMESPACE
class QIODevice;
@@ -134,7 +136,7 @@ public:
QByteArray downloadBuffer;
QIODevice *outgoingData;
- QSharedPointer<QRingBuffer> outgoingDataBuffer;
+ std::shared_ptr<QRingBuffer> outgoingDataBuffer;
QByteArray requestData;
static void downloadProgress(emscripten_fetch_t *fetch);