summaryrefslogtreecommitdiffstats
path: root/src/corelib/serialization
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2020-11-07 08:05:34 -0800
committerThiago Macieira <thiago.macieira@intel.com>2020-12-09 20:20:08 +0000
commit2bed336599dddd7e7c3cef73107c5ca3e6d6ab27 (patch)
treec2bf9b733890314193a67f6c9489a7c544c1eeba /src/corelib/serialization
parentfa0dc8313506b993ef0bd43ea5f38739cd58bcbd (diff)
QCborStreamReader: move helper function to the only place it's used
Simplifies the code a little bit Pick-to: 5.15 6.0 Change-Id: I7b9b97ae9b32412abdc6fffd164545632be4590a Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/corelib/serialization')
-rw-r--r--src/corelib/serialization/qcborstreamreader.cpp42
1 files changed, 17 insertions, 25 deletions
diff --git a/src/corelib/serialization/qcborstreamreader.cpp b/src/corelib/serialization/qcborstreamreader.cpp
index f1bea6a1f1..460813cece 100644
--- a/src/corelib/serialization/qcborstreamreader.cpp
+++ b/src/corelib/serialization/qcborstreamreader.cpp
@@ -647,27 +647,6 @@ public:
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 {
union {
char *ptr;
@@ -1558,10 +1537,23 @@ QCborStreamReaderPrivate::readStringChunk(ReadStringChunk params)
if (result.data < 0)
return result; // error
- if (device)
- updateBufferAfterString(0, len);
- else
- bufferStart += len;
+ // adjust the buffers after we're done reading the string
+ bufferStart += len;
+ if (device) {
+ 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();
result.status = QCborStreamReader::Ok;