QRingBuffer: overload append() for rvalues
The majority of append() callers in QtBase pass rvalues, so overload append() to avoid the need for manipulating QBA's atomic ref counts. Also adjust a caller that could pass by rvalue, but didn't, to do so. Pick-to: 6.3 Change-Id: I3d9e60b0d04ef837bfdc526e1f0f691a151006f9 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>bb10
parent
63a35898f4
commit
758a830f7e
|
|
@ -363,6 +363,21 @@ void QRingBuffer::append(const QByteArray &qba)
|
|||
bufferSize += qba.size();
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
|
||||
Append a new buffer to the end
|
||||
*/
|
||||
void QRingBuffer::append(QByteArray &&qba)
|
||||
{
|
||||
const auto qbaSize = qba.size();
|
||||
if (bufferSize != 0 || buffers.isEmpty())
|
||||
buffers.emplace_back(std::move(qba));
|
||||
else
|
||||
buffers.last().assign(std::move(qba));
|
||||
bufferSize += qbaSize;
|
||||
}
|
||||
|
||||
qint64 QRingBuffer::readLine(char *data, qint64 maxLength)
|
||||
{
|
||||
Q_ASSERT(data != nullptr && maxLength > 1);
|
||||
|
|
|
|||
|
|
@ -81,6 +81,10 @@ public:
|
|||
chunk(qba), headOffset(0), tailOffset(qba.size())
|
||||
{
|
||||
}
|
||||
explicit QRingChunk(QByteArray &&qba) noexcept :
|
||||
chunk(std::move(qba)), headOffset(0), tailOffset(chunk.size())
|
||||
{
|
||||
}
|
||||
|
||||
inline QRingChunk &operator=(const QRingChunk &other) noexcept
|
||||
{
|
||||
|
|
@ -161,6 +165,12 @@ public:
|
|||
headOffset = 0;
|
||||
tailOffset = qba.size();
|
||||
}
|
||||
void assign(QByteArray &&qba)
|
||||
{
|
||||
chunk = std::move(qba);
|
||||
headOffset = 0;
|
||||
tailOffset = chunk.size();
|
||||
}
|
||||
inline void reset()
|
||||
{
|
||||
headOffset = tailOffset = 0;
|
||||
|
|
@ -248,6 +258,7 @@ public:
|
|||
Q_CORE_EXPORT qint64 peek(char *data, qint64 maxLength, qint64 pos = 0) const;
|
||||
Q_CORE_EXPORT void append(const char *data, qint64 size);
|
||||
Q_CORE_EXPORT void append(const QByteArray &qba);
|
||||
Q_CORE_EXPORT void append(QByteArray &&qba);
|
||||
|
||||
inline qint64 skip(qint64 length) {
|
||||
qint64 bytesToSkip = qMin(length, bufferSize);
|
||||
|
|
|
|||
|
|
@ -1190,7 +1190,7 @@ void QSocks5SocketEnginePrivate::_q_controlSocketReadNotification()
|
|||
}
|
||||
if (buf.size()) {
|
||||
QSOCKS5_DEBUG << dump(buf);
|
||||
connectData->readBuffer.append(buf);
|
||||
connectData->readBuffer.append(std::move(buf));
|
||||
emitReadNotification();
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
Loading…
Reference in New Issue