summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2021-12-12 17:04:26 +0100
committerMarc Mutz <marc.mutz@qt.io>2021-12-16 00:01:41 +0100
commit81bf3e68b9edb6fc8635ab5520f86df9c8d6ef04 (patch)
tree9a111d74c4891cf7c7c88614e1a247d2a5bad5b4 /src/corelib/io
parent758a830f7ef23ebea542bc6dad4490b29e22bab8 (diff)
Make QRingBuffer a move-only type
There's no sense in copying a ring buffer. Moving is enough. This marks an important step on the way to preventing accidental copies of ring buffer content, because the 'QList buffers' member can now no longer be implicitly shared. While the compiler will still emit the code for detach()ing, it will now never be executed. Pick-to: 6.3 Change-Id: I968bfe3e50c46720ed4baca55c99c1f9c518f653 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qiodevice.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp
index e362535852..57d26884ee 100644
--- a/src/corelib/io/qiodevice.cpp
+++ b/src/corelib/io/qiodevice.cpp
@@ -703,15 +703,18 @@ void QIODevice::setCurrentReadChannel(int channel)
void QIODevicePrivate::setReadChannelCount(int count)
{
if (count > readBuffers.size()) {
+ readBuffers.reserve(count);
+
// If readBufferChunkSize is zero, we should bypass QIODevice's
// read buffers, even if the QIODeviceBase::Unbuffered flag is not
// set when opened. However, if a read transaction is started or
// ungetChar() is called, we still have to use the internal buffer.
// To support these cases, pass a default value to the QRingBuffer
// constructor.
- readBuffers.insert(readBuffers.end(), count - readBuffers.size(),
- QRingBuffer(readBufferChunkSize != 0 ? readBufferChunkSize
- : QIODEVICE_BUFFERSIZE));
+
+ while (readBuffers.size() < count)
+ readBuffers.emplace_back(readBufferChunkSize != 0 ? readBufferChunkSize
+ : QIODEVICE_BUFFERSIZE);
} else {
readBuffers.resize(count);
}
@@ -762,8 +765,9 @@ void QIODevicePrivate::setWriteChannelCount(int count)
// If writeBufferChunkSize is zero (default value), we don't use
// QIODevice's write buffers.
if (writeBufferChunkSize != 0) {
- writeBuffers.insert(writeBuffers.end(), count - writeBuffers.size(),
- QRingBuffer(writeBufferChunkSize));
+ writeBuffers.reserve(count);
+ while (writeBuffers.size() < count)
+ writeBuffers.emplace_back(writeBufferChunkSize);
}
} else {
writeBuffers.resize(count);