QCborStreamReader: move helper function to the only place it's used
Simplifies the code a little bit Change-Id: I7b9b97ae9b32412abdc6fffd164545632be4590a Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> (cherry picked from commit 2bed336599dddd7e7c3cef73107c5ca3e6d6ab27) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
72bf3234e4
commit
cd600d95b1
@ -647,27 +647,6 @@ public:
|
|||||||
lastError = QCborError { QCborError::Code(int(err)) };
|
lastError = QCborError { QCborError::Code(int(err)) };
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateBufferAfterString(qsizetype offset, qsizetype size)
|
|
||||||
{
|
|
||||||
Q_ASSERT(device);
|
|
||||||
|
|
||||||
bufferStart += offset;
|
|
||||||
qsizetype newStart = bufferStart + size;
|
|
||||||
qsizetype remainingInBuffer = buffer.size() - newStart;
|
|
||||||
|
|
||||||
if (remainingInBuffer <= 0) {
|
|
||||||
// We've read from the QIODevice more than what was in the buffer.
|
|
||||||
buffer.truncate(0);
|
|
||||||
} else {
|
|
||||||
// There's still data buffered, but we need to move it around.
|
|
||||||
char *ptr = buffer.data();
|
|
||||||
memmove(ptr, ptr + newStart, remainingInBuffer);
|
|
||||||
buffer.truncate(remainingInBuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
bufferStart = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ReadStringChunk {
|
struct ReadStringChunk {
|
||||||
union {
|
union {
|
||||||
char *ptr;
|
char *ptr;
|
||||||
@ -1558,10 +1537,23 @@ QCborStreamReaderPrivate::readStringChunk(ReadStringChunk params)
|
|||||||
if (result.data < 0)
|
if (result.data < 0)
|
||||||
return result; // error
|
return result; // error
|
||||||
|
|
||||||
if (device)
|
// adjust the buffers after we're done reading the string
|
||||||
updateBufferAfterString(0, len);
|
bufferStart += len;
|
||||||
else
|
if (device) {
|
||||||
bufferStart += len;
|
qsizetype remainingInBuffer = buffer.size() - bufferStart;
|
||||||
|
|
||||||
|
if (remainingInBuffer <= 0) {
|
||||||
|
// We've read from the QIODevice more than what was in the buffer.
|
||||||
|
buffer.truncate(0);
|
||||||
|
} else {
|
||||||
|
// There's still data buffered, but we need to move it around.
|
||||||
|
char *ptr = buffer.data();
|
||||||
|
memmove(ptr, ptr + bufferStart, remainingInBuffer);
|
||||||
|
buffer.truncate(remainingInBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
bufferStart = 0;
|
||||||
|
}
|
||||||
|
|
||||||
preread();
|
preread();
|
||||||
result.status = QCborStreamReader::Ok;
|
result.status = QCborStreamReader::Ok;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user