diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2014-04-03 11:02:08 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-04-07 12:11:47 +0200 |
commit | 0ff6f175ecf7b60529346ddbc2740a8419d07195 (patch) | |
tree | 588a92d4163a0fe62399582dabb3801327fe7032 | |
parent | 89fb2271f377d1194f3311124daef97504e6ead9 (diff) |
Add QNonContiguousByteDeviceFactory::createShared()
for more efficient creation of QNonContiguousByteDevices held in shared pointers.
Use the new functions in QNetworkAccessBackend::createUploadByteDevice()
and QNetworkReplyHttpImplPrivate::createUploadByteDevice().
Change-Id: I8a3c76f7c8d5926850303992c77e9382a39a55e8
Reviewed-by: Richard J. Moore <rich@kde.org>
-rw-r--r-- | src/corelib/io/qnoncontiguousbytedevice.cpp | 39 | ||||
-rw-r--r-- | src/corelib/io/qnoncontiguousbytedevice_p.h | 6 | ||||
-rw-r--r-- | src/network/access/qnetworkaccessbackend.cpp | 4 | ||||
-rw-r--r-- | src/network/access/qnetworkreplyhttpimpl.cpp | 4 |
4 files changed, 49 insertions, 4 deletions
diff --git a/src/corelib/io/qnoncontiguousbytedevice.cpp b/src/corelib/io/qnoncontiguousbytedevice.cpp index b1e4dd7584..4c5fb38c67 100644 --- a/src/corelib/io/qnoncontiguousbytedevice.cpp +++ b/src/corelib/io/qnoncontiguousbytedevice.cpp @@ -506,6 +506,25 @@ QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QIODevice *dev } /*! + Create a QNonContiguousByteDevice out of a QIODevice, return it in a QSharedPointer. + For QFile, QBuffer and all other QIODevice, sequential or not. + + \internal +*/ +QSharedPointer<QNonContiguousByteDevice> QNonContiguousByteDeviceFactory::createShared(QIODevice *device) +{ + // shortcut if it is a QBuffer + if (QBuffer *buffer = qobject_cast<QBuffer*>(device)) + return QSharedPointer<QNonContiguousByteDeviceBufferImpl>::create(buffer); + + // ### FIXME special case if device is a QFile that supports map() + // then we can actually deal with the file without using read/peek + + // generic QIODevice + return QSharedPointer<QNonContiguousByteDeviceIoDeviceImpl>::create(device); // FIXME +} + +/*! \fn static QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QSharedPointer<QRingBuffer> ringBuffer) Create a QNonContiguousByteDevice out of a QRingBuffer. @@ -518,6 +537,16 @@ QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QSharedPointer } /*! + Create a QNonContiguousByteDevice out of a QRingBuffer, return it in a QSharedPointer. + + \internal +*/ +QSharedPointer<QNonContiguousByteDevice> QNonContiguousByteDeviceFactory::createShared(QSharedPointer<QRingBuffer> ringBuffer) +{ + return QSharedPointer<QNonContiguousByteDeviceRingBufferImpl>::create(qMove(ringBuffer)); +} + +/*! \fn static QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QByteArray *byteArray) Create a QNonContiguousByteDevice out of a QByteArray. @@ -530,6 +559,16 @@ QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QByteArray *by } /*! + Create a QNonContiguousByteDevice out of a QByteArray. + + \internal +*/ +QSharedPointer<QNonContiguousByteDevice> QNonContiguousByteDeviceFactory::createShared(QByteArray *byteArray) +{ + return QSharedPointer<QNonContiguousByteDeviceByteArrayImpl>::create(byteArray); +} + +/*! \fn static QIODevice* QNonContiguousByteDeviceFactory::wrap(QNonContiguousByteDevice* byteDevice) Wrap the \a byteDevice (possibly again) into a QIODevice. diff --git a/src/corelib/io/qnoncontiguousbytedevice_p.h b/src/corelib/io/qnoncontiguousbytedevice_p.h index 4606ac2686..1e746db80f 100644 --- a/src/corelib/io/qnoncontiguousbytedevice_p.h +++ b/src/corelib/io/qnoncontiguousbytedevice_p.h @@ -90,8 +90,14 @@ class Q_CORE_EXPORT QNonContiguousByteDeviceFactory { public: static QNonContiguousByteDevice* create(QIODevice *device); + static QSharedPointer<QNonContiguousByteDevice> createShared(QIODevice *device); + static QNonContiguousByteDevice* create(QByteArray *byteArray); + static QSharedPointer<QNonContiguousByteDevice> createShared(QByteArray *byteArray); + static QNonContiguousByteDevice* create(QSharedPointer<QRingBuffer> ringBuffer); + static QSharedPointer<QNonContiguousByteDevice> createShared(QSharedPointer<QRingBuffer> ringBuffer); + static QIODevice* wrap(QNonContiguousByteDevice* byteDevice); }; diff --git a/src/network/access/qnetworkaccessbackend.cpp b/src/network/access/qnetworkaccessbackend.cpp index 3c5e1e80a8..f387559cb3 100644 --- a/src/network/access/qnetworkaccessbackend.cpp +++ b/src/network/access/qnetworkaccessbackend.cpp @@ -130,9 +130,9 @@ QStringList QNetworkAccessManagerPrivate::backendSupportedSchemes() const QNonContiguousByteDevice* QNetworkAccessBackend::createUploadByteDevice() { if (reply->outgoingDataBuffer) - uploadByteDevice = QSharedPointer<QNonContiguousByteDevice>(QNonContiguousByteDeviceFactory::create(reply->outgoingDataBuffer)); + uploadByteDevice = QNonContiguousByteDeviceFactory::createShared(reply->outgoingDataBuffer); else if (reply->outgoingData) { - uploadByteDevice = QSharedPointer<QNonContiguousByteDevice>(QNonContiguousByteDeviceFactory::create(reply->outgoingData)); + uploadByteDevice = QNonContiguousByteDeviceFactory::createShared(reply->outgoingData); } else { return 0; } diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp index 7dc8e6ac73..bf49b97b30 100644 --- a/src/network/access/qnetworkreplyhttpimpl.cpp +++ b/src/network/access/qnetworkreplyhttpimpl.cpp @@ -1844,9 +1844,9 @@ QNonContiguousByteDevice* QNetworkReplyHttpImplPrivate::createUploadByteDevice() Q_Q(QNetworkReplyHttpImpl); if (outgoingDataBuffer) - uploadByteDevice = QSharedPointer<QNonContiguousByteDevice>(QNonContiguousByteDeviceFactory::create(outgoingDataBuffer)); + uploadByteDevice = QNonContiguousByteDeviceFactory::createShared(outgoingDataBuffer); else if (outgoingData) { - uploadByteDevice = QSharedPointer<QNonContiguousByteDevice>(QNonContiguousByteDeviceFactory::create(outgoingData)); + uploadByteDevice = QNonContiguousByteDeviceFactory::createShared(outgoingData); } else { return 0; } |