QRingBuffer: optimize and simplify QRingChunk::toByteArray() futher
- use sliced() instead of mid(), since we know we call sliced() in-contract - replace the manual memmove() with calls to QBA::remove(), but first resize() to tailOffset, and only then remove(0, headOffset), so we only move Chunk::size() bytes, as the old code did - don't bother updating the offset members, as we're restricted to rvalues now, and we only need to leave behind a partially-formed object This code shows that we desperately need QBA::slice() and/or an rvalue overload of QBA::sliced(), cf. QTBUG-99218. Add a comment to use these functions when they become available. Change-Id: I5d8c7363d443dff69338f6f6a7b4bff9957917ec Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Alex Trotsenko <alex1973tr@gmail.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>bb10
parent
ab24390804
commit
612417ea70
|
|
@ -71,18 +71,13 @@ void QRingChunk::detach()
|
|||
|
||||
QByteArray QRingChunk::toByteArray() &&
|
||||
{
|
||||
// ### Replace with std::move(chunk).sliced(head(), size()) once sliced()&& is available
|
||||
if (headOffset != 0 || tailOffset != chunk.size()) {
|
||||
if (isShared())
|
||||
return chunk.mid(headOffset, size());
|
||||
|
||||
if (headOffset != 0) {
|
||||
char *ptr = chunk.data();
|
||||
::memmove(ptr, ptr + headOffset, size());
|
||||
tailOffset -= headOffset;
|
||||
headOffset = 0;
|
||||
}
|
||||
return chunk.sliced(head(), size());
|
||||
|
||||
chunk.resize(tailOffset);
|
||||
chunk.remove(0, headOffset);
|
||||
}
|
||||
|
||||
return std::move(chunk);
|
||||
|
|
|
|||
Loading…
Reference in New Issue