diff --git a/src/corelib/io/qnoncontiguousbytedevice.cpp b/src/corelib/io/qnoncontiguousbytedevice.cpp index 283253eb024..2bb41651554 100644 --- a/src/corelib/io/qnoncontiguousbytedevice.cpp +++ b/src/corelib/io/qnoncontiguousbytedevice.cpp @@ -100,11 +100,13 @@ 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() +QNonContiguousByteDeviceBufferImpl::QNonContiguousByteDeviceBufferImpl(QBuffer *b) + : QNonContiguousByteDevice(), + buffer(b), + byteArray(QByteArray::fromRawData(buffer->buffer().constData() + buffer->pos(), + buffer->size() - buffer->pos())), + arrayImpl(new QNonContiguousByteDeviceByteArrayImpl(&byteArray)) { - buffer = b; - byteArray = QByteArray::fromRawData(buffer->buffer().constData() + buffer->pos(), buffer->size() - buffer->pos()); - arrayImpl = new QNonContiguousByteDeviceByteArrayImpl(&byteArray); arrayImpl->setParent(this); connect(arrayImpl, &QNonContiguousByteDevice::readyRead, this, &QNonContiguousByteDevice::readyRead); @@ -141,9 +143,9 @@ qint64 QNonContiguousByteDeviceBufferImpl::size() const return arrayImpl->size(); } -QNonContiguousByteDeviceByteArrayImpl::QNonContiguousByteDeviceByteArrayImpl(QByteArray *ba) : QNonContiguousByteDevice(), currentPosition(0) +QNonContiguousByteDeviceByteArrayImpl::QNonContiguousByteDeviceByteArrayImpl(QByteArray *ba) + : QNonContiguousByteDevice(), byteArray(ba), currentPosition(0) { - byteArray = ba; } QNonContiguousByteDeviceByteArrayImpl::~QNonContiguousByteDeviceByteArrayImpl() @@ -247,12 +249,15 @@ qint64 QNonContiguousByteDeviceRingBufferImpl::size() const QNonContiguousByteDeviceIoDeviceImpl::QNonContiguousByteDeviceIoDeviceImpl(QIODevice *d) : QNonContiguousByteDevice(), - currentReadBuffer(nullptr), currentReadBufferSize(16*1024), - currentReadBufferAmount(0), currentReadBufferPosition(0), totalAdvancements(0), - eof(false) + device(d), + currentReadBuffer(nullptr), + currentReadBufferSize(16 * 1024), + currentReadBufferAmount(0), + currentReadBufferPosition(0), + totalAdvancements(0), + eof(false), + initialPosition(d->pos()) { - device = d; - initialPosition = d->pos(); connect(device, &QIODevice::readyRead, this, &QNonContiguousByteDevice::readyRead); connect(device, &QIODevice::readChannelFinished, this, @@ -266,7 +271,7 @@ QNonContiguousByteDeviceIoDeviceImpl::~QNonContiguousByteDeviceIoDeviceImpl() const char *QNonContiguousByteDeviceIoDeviceImpl::readPointer(qint64 maximumLength, qint64 &len) { - if (eof == true) { + if (eof) { len = -1; return nullptr; } @@ -282,7 +287,8 @@ const char *QNonContiguousByteDeviceIoDeviceImpl::readPointer(qint64 maximumLeng return currentReadBuffer->data() + currentReadBufferPosition; } - qint64 haveRead = device->read(currentReadBuffer->data(), qMin(maximumLength, currentReadBufferSize)); + qint64 haveRead = device->read(currentReadBuffer->data(), + qMin(maximumLength, currentReadBufferSize)); if ((haveRead == -1) || (haveRead == 0 && device->atEnd() && !device->isSequential())) { eof = true; @@ -316,7 +322,7 @@ bool QNonContiguousByteDeviceIoDeviceImpl::advanceReadPointer(qint64 amount) if (currentReadBufferPosition > currentReadBufferAmount) { qint64 i = currentReadBufferPosition - currentReadBufferAmount; while (i > 0) { - if (device->getChar(nullptr) == false) { + if (!device->getChar(nullptr)) { emit readProgress(totalAdvancements - i, size()); return false; // ### FIXME handle eof } @@ -332,7 +338,7 @@ bool QNonContiguousByteDeviceIoDeviceImpl::advanceReadPointer(qint64 amount) bool QNonContiguousByteDeviceIoDeviceImpl::atEnd() const { - return eof == true; + return eof; } bool QNonContiguousByteDeviceIoDeviceImpl::reset() @@ -371,18 +377,16 @@ qint64 QNonContiguousByteDeviceIoDeviceImpl::pos() const return device->pos(); } -QByteDeviceWrappingIoDevice::QByteDeviceWrappingIoDevice(QNonContiguousByteDevice *bd) : QIODevice((QObject*)nullptr) +QByteDeviceWrappingIoDevice::QByteDeviceWrappingIoDevice(QNonContiguousByteDevice *bd) + : QIODevice(nullptr), byteDevice(bd) { - byteDevice = bd; connect(bd, SIGNAL(readyRead()), SIGNAL(readyRead())); open(ReadOnly); } QByteDeviceWrappingIoDevice::~QByteDeviceWrappingIoDevice() -{ - -} + = default; bool QByteDeviceWrappingIoDevice::isSequential() const { @@ -487,9 +491,10 @@ std::shared_ptr QNonContiguousByteDeviceFactory::creat \internal */ -QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(std::shared_ptr ringBuffer) +QNonContiguousByteDevice * +QNonContiguousByteDeviceFactory::create(std::shared_ptr ringBuffer) { - return new QNonContiguousByteDeviceRingBufferImpl(ringBuffer); + return new QNonContiguousByteDeviceRingBufferImpl(std::move(ringBuffer)); } /*! @@ -497,7 +502,8 @@ QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(std::shared_pt \internal */ -std::shared_ptr QNonContiguousByteDeviceFactory::createShared(std::shared_ptr ringBuffer) +std::shared_ptr +QNonContiguousByteDeviceFactory::createShared(std::shared_ptr ringBuffer) { return std::make_shared(std::move(ringBuffer)); } @@ -519,7 +525,8 @@ QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QByteArray *by \internal */ -std::shared_ptr QNonContiguousByteDeviceFactory::createShared(QByteArray *byteArray) +std::shared_ptr +QNonContiguousByteDeviceFactory::createShared(QByteArray *byteArray) { return std::make_shared(byteArray); }