Simplify QRingBuffer::peek()
Use a range-based for loop instead of index-based access. Change-Id: Ie43aee540062eec4800f39915ebd42d5a3cae4b3 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>bb10
parent
9f33b84b09
commit
cdc30acbde
|
|
@ -312,12 +312,14 @@ qint64 QRingBuffer::peek(char *data, qint64 maxLength, qint64 pos) const
|
|||
Q_ASSERT(maxLength >= 0 && pos >= 0);
|
||||
|
||||
qint64 readSoFar = 0;
|
||||
for (int i = 0; readSoFar < maxLength && i < buffers.size(); ++i) {
|
||||
qint64 blockLength = buffers[i].size();
|
||||
for (const QRingChunk &chunk : buffers) {
|
||||
if (readSoFar == maxLength)
|
||||
break;
|
||||
|
||||
qint64 blockLength = chunk.size();
|
||||
if (pos < blockLength) {
|
||||
blockLength = qMin(blockLength - pos, maxLength - readSoFar);
|
||||
memcpy(data + readSoFar, buffers[i].data() + pos, blockLength);
|
||||
memcpy(data + readSoFar, chunk.data() + pos, blockLength);
|
||||
readSoFar += blockLength;
|
||||
pos = 0;
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue