QNonContiguousByteDeviceByteArrayImpl: store value not pointer
Storing a pointer was fine when used with the QBuffer version, but that means you have to keep the QBArray alive outside the class itself. Just store the value and it is a little easier to use. Changes in this cherry-pick: The dev patch chain has the test update in the wrong commit, so cherry-picked it along with this. And apparently I also forgot to commit a bug-fix to this commit as well, the bug anyway disappeared in dev when I deleted the class and redirected everything to the ByteArray class. Change-Id: Ic02e0b4627fde2b5fdd7e5fb69a94e06aa768ab9 Reviewed-by: Alexey Edelev <alexey.edelev@qt.io> Reviewed-by: Dennis Oberst <dennis.oberst@qt.io> (cherry picked from commit 67140afca21efae75aad35f63ca1d7211fe6ec3a) Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
parent
c250c59f7c
commit
a903414898
@ -6,6 +6,8 @@
|
||||
#include <qdebug.h>
|
||||
#include <qfile.h>
|
||||
|
||||
#include <utility>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
/*!
|
||||
@ -102,10 +104,9 @@ QNonContiguousByteDevice::~QNonContiguousByteDevice()
|
||||
// FIXME we should scrap this whole implementation and instead change the ByteArrayImpl to be able to cope with sub-arrays?
|
||||
QNonContiguousByteDeviceBufferImpl::QNonContiguousByteDeviceBufferImpl(QBuffer *b)
|
||||
: QNonContiguousByteDevice(),
|
||||
buffer(b),
|
||||
byteArray(QByteArray::fromRawData(buffer->buffer().constData() + buffer->pos(),
|
||||
buffer->size() - buffer->pos())),
|
||||
arrayImpl(new QNonContiguousByteDeviceByteArrayImpl(&byteArray))
|
||||
byteArray(QByteArray::fromRawData(b->buffer().constData() + b->pos(),
|
||||
b->buffer().size() - b->pos())),
|
||||
arrayImpl(new QNonContiguousByteDeviceByteArrayImpl(b->buffer().sliced(b->pos())))
|
||||
{
|
||||
arrayImpl->setParent(this);
|
||||
connect(arrayImpl, &QNonContiguousByteDevice::readyRead, this,
|
||||
@ -143,8 +144,8 @@ qint64 QNonContiguousByteDeviceBufferImpl::size() const
|
||||
return arrayImpl->size();
|
||||
}
|
||||
|
||||
QNonContiguousByteDeviceByteArrayImpl::QNonContiguousByteDeviceByteArrayImpl(QByteArray *ba)
|
||||
: QNonContiguousByteDevice(), byteArray(ba), currentPosition(0)
|
||||
QNonContiguousByteDeviceByteArrayImpl::QNonContiguousByteDeviceByteArrayImpl(QByteArray ba)
|
||||
: QNonContiguousByteDevice(), byteArray(std::move(ba)), currentPosition(0)
|
||||
{
|
||||
}
|
||||
|
||||
@ -164,7 +165,7 @@ const char* QNonContiguousByteDeviceByteArrayImpl::readPointer(qint64 maximumLen
|
||||
else
|
||||
len = size() - currentPosition;
|
||||
|
||||
return byteArray->constData() + currentPosition;
|
||||
return byteArray.constData() + currentPosition;
|
||||
}
|
||||
|
||||
bool QNonContiguousByteDeviceByteArrayImpl::advanceReadPointer(qint64 amount)
|
||||
@ -187,7 +188,7 @@ bool QNonContiguousByteDeviceByteArrayImpl::reset()
|
||||
|
||||
qint64 QNonContiguousByteDeviceByteArrayImpl::size() const
|
||||
{
|
||||
return byteArray->size();
|
||||
return byteArray.size();
|
||||
}
|
||||
|
||||
qint64 QNonContiguousByteDeviceByteArrayImpl::pos() const
|
||||
@ -515,7 +516,7 @@ QNonContiguousByteDeviceFactory::createShared(std::shared_ptr<QRingBuffer> ringB
|
||||
|
||||
\internal
|
||||
*/
|
||||
QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QByteArray *byteArray)
|
||||
QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(const QByteArray &byteArray)
|
||||
{
|
||||
return new QNonContiguousByteDeviceByteArrayImpl(byteArray);
|
||||
}
|
||||
@ -526,7 +527,7 @@ QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QByteArray *by
|
||||
\internal
|
||||
*/
|
||||
std::shared_ptr<QNonContiguousByteDevice>
|
||||
QNonContiguousByteDeviceFactory::createShared(QByteArray *byteArray)
|
||||
QNonContiguousByteDeviceFactory::createShared(const QByteArray &byteArray)
|
||||
{
|
||||
return std::make_shared<QNonContiguousByteDeviceByteArrayImpl>(byteArray);
|
||||
}
|
||||
|
@ -52,8 +52,8 @@ public:
|
||||
static QNonContiguousByteDevice *create(QIODevice *device);
|
||||
static std::shared_ptr<QNonContiguousByteDevice> createShared(QIODevice *device);
|
||||
|
||||
static QNonContiguousByteDevice *create(QByteArray *byteArray);
|
||||
static std::shared_ptr<QNonContiguousByteDevice> createShared(QByteArray *byteArray);
|
||||
static QNonContiguousByteDevice *create(const QByteArray &byteArray);
|
||||
static std::shared_ptr<QNonContiguousByteDevice> createShared(const QByteArray &byteArray);
|
||||
|
||||
static QNonContiguousByteDevice *create(std::shared_ptr<QRingBuffer> ringBuffer);
|
||||
static std::shared_ptr<QNonContiguousByteDevice> createShared(std::shared_ptr<QRingBuffer> ringBuffer);
|
||||
@ -68,7 +68,7 @@ class QNonContiguousByteDeviceByteArrayImpl : public QNonContiguousByteDevice
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QNonContiguousByteDeviceByteArrayImpl(QByteArray *ba);
|
||||
explicit QNonContiguousByteDeviceByteArrayImpl(QByteArray ba);
|
||||
~QNonContiguousByteDeviceByteArrayImpl();
|
||||
const char *readPointer(qint64 maximumLength, qint64 &len) override;
|
||||
bool advanceReadPointer(qint64 amount) override;
|
||||
@ -78,7 +78,7 @@ public:
|
||||
qint64 pos() const override;
|
||||
|
||||
protected:
|
||||
QByteArray *byteArray;
|
||||
QByteArray byteArray;
|
||||
qint64 currentPosition;
|
||||
};
|
||||
|
||||
@ -137,7 +137,6 @@ public:
|
||||
qint64 size() const override;
|
||||
|
||||
protected:
|
||||
QBuffer *buffer;
|
||||
QByteArray byteArray;
|
||||
QNonContiguousByteDeviceByteArrayImpl *arrayImpl;
|
||||
};
|
||||
|
@ -249,7 +249,7 @@ void tst_QHttpNetworkConnection::put()
|
||||
QHttpNetworkRequest request(protocol + host + path, QHttpNetworkRequest::Put);
|
||||
|
||||
QByteArray array = data.toLatin1();
|
||||
QNonContiguousByteDevice *bd = QNonContiguousByteDeviceFactory::create(&array);
|
||||
QNonContiguousByteDevice *bd = QNonContiguousByteDeviceFactory::create(array);
|
||||
bd->setParent(this);
|
||||
request.setUploadByteDevice(bd);
|
||||
|
||||
@ -331,7 +331,7 @@ void tst_QHttpNetworkConnection::post()
|
||||
QHttpNetworkRequest request(protocol + host + path, QHttpNetworkRequest::Post);
|
||||
|
||||
QByteArray array = data.toLatin1();
|
||||
QNonContiguousByteDevice *bd = QNonContiguousByteDeviceFactory::create(&array);
|
||||
QNonContiguousByteDevice *bd = QNonContiguousByteDeviceFactory::create(array);
|
||||
bd->setParent(this);
|
||||
request.setUploadByteDevice(bd);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user