diff options
author | Mårten Nordheim <marten.nordheim@qt.io> | 2023-09-08 13:38:02 +0200 |
---|---|---|
committer | Mårten Nordheim <marten.nordheim@qt.io> | 2023-10-17 21:23:41 +0200 |
commit | 45a3fa01015f154453c8bceea98f3f8864e28a3d (patch) | |
tree | 7cc730882029222256b4bafe026b0621f1eba637 /src/corelib/io | |
parent | 3e6b42ae9dbf4f90ba890d78a4c49f9936f4976b (diff) |
Clean up qnoncontiguousbytedevice.cpp
Mostly applying clang-format and clang-tidy fixits for:
- Redundant code (e.g. bool == true/false)
- Use member initializer list
- std::move for parameters taken by copy
Change-Id: I3b9a7f01db67291f889b42346a95c55ad74f054c
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'src/corelib/io')
-rw-r--r-- | src/corelib/io/qnoncontiguousbytedevice.cpp | 55 |
1 files changed, 31 insertions, 24 deletions
diff --git a/src/corelib/io/qnoncontiguousbytedevice.cpp b/src/corelib/io/qnoncontiguousbytedevice.cpp index 283253eb02..2bb4165155 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<QNonContiguousByteDevice> QNonContiguousByteDeviceFactory::creat \internal */ -QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(std::shared_ptr<QRingBuffer> ringBuffer) +QNonContiguousByteDevice * +QNonContiguousByteDeviceFactory::create(std::shared_ptr<QRingBuffer> 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<QNonContiguousByteDevice> QNonContiguousByteDeviceFactory::createShared(std::shared_ptr<QRingBuffer> ringBuffer) +std::shared_ptr<QNonContiguousByteDevice> +QNonContiguousByteDeviceFactory::createShared(std::shared_ptr<QRingBuffer> ringBuffer) { return std::make_shared<QNonContiguousByteDeviceRingBufferImpl>(std::move(ringBuffer)); } @@ -519,7 +525,8 @@ QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QByteArray *by \internal */ -std::shared_ptr<QNonContiguousByteDevice> QNonContiguousByteDeviceFactory::createShared(QByteArray *byteArray) +std::shared_ptr<QNonContiguousByteDevice> +QNonContiguousByteDeviceFactory::createShared(QByteArray *byteArray) { return std::make_shared<QNonContiguousByteDeviceByteArrayImpl>(byteArray); } |