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>
bb10
Marc Mutz 2014-04-03 11:02:08 +02:00 committed by The Qt Project
parent 89fb2271f3
commit 0ff6f175ec
4 changed files with 49 additions and 4 deletions

View File

@ -505,6 +505,25 @@ QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QIODevice *dev
return new QNonContiguousByteDeviceIoDeviceImpl(device); // FIXME
}
/*!
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)
@ -517,6 +536,16 @@ QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QSharedPointer
return new QNonContiguousByteDeviceRingBufferImpl(ringBuffer);
}
/*!
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)
@ -529,6 +558,16 @@ QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QByteArray *by
return new QNonContiguousByteDeviceByteArrayImpl(byteArray);
}
/*!
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)

View File

@ -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);
};

View File

@ -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;
}

View File

@ -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;
}