summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qiodevice.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/io/qiodevice.cpp')
-rw-r--r--src/corelib/io/qiodevice.cpp46
1 files changed, 28 insertions, 18 deletions
diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp
index c4fc040685..52a78ad1c4 100644
--- a/src/corelib/io/qiodevice.cpp
+++ b/src/corelib/io/qiodevice.cpp
@@ -747,6 +747,18 @@ void QIODevicePrivate::setWriteChannelCount(int count)
}
/*!
+ \internal
+*/
+bool QIODevicePrivate::allWriteBuffersEmpty() const
+{
+ for (const QRingBuffer &ringBuffer : writeBuffers) {
+ if (!ringBuffer.isEmpty())
+ return false;
+ }
+ return true;
+}
+
+/*!
Opens the device and sets its OpenMode to \a mode. Returns \c true if successful;
otherwise returns \c false. This function should be called from any
reimplementations of open() or other functions that open the device.
@@ -1156,31 +1168,29 @@ QByteArray QIODevice::read(qint64 maxSize)
Q_D(QIODevice);
QByteArray result;
- CHECK_MAXLEN(read, result);
- CHECK_MAXBYTEARRAYSIZE(read);
-
#if defined QIODEVICE_DEBUG
printf("%p QIODevice::read(%lld), d->pos = %lld, d->buffer.size() = %lld\n",
this, maxSize, d->pos, d->buffer.size());
#endif
- qint64 readBytes = 0;
- if (maxSize) {
- result.resize(int(maxSize));
- if (!result.size()) {
- // If resize fails, read incrementally.
- qint64 readResult;
- do {
- result.resize(int(qMin(maxSize, qint64(result.size() + d->readBufferChunkSize))));
- readResult = read(result.data() + readBytes, result.size() - readBytes);
- if (readResult > 0 || readBytes == 0)
- readBytes += readResult;
- } while (readResult == d->readBufferChunkSize);
- } else {
- readBytes = read(result.data(), result.size());
- }
+ // Try to prevent the data from being copied, if we have a chunk
+ // with the same size in the read buffer.
+ if (maxSize == d->buffer.nextDataBlockSize() && !d->transactionStarted
+ && (d->openMode & (QIODevice::ReadOnly | QIODevice::Text)) == QIODevice::ReadOnly) {
+ result = d->buffer.read();
+ if (!d->isSequential())
+ d->pos += maxSize;
+ if (d->buffer.isEmpty())
+ readData(nullptr, 0);
+ return result;
}
+ CHECK_MAXLEN(read, result);
+ CHECK_MAXBYTEARRAYSIZE(read);
+
+ result.resize(int(maxSize));
+ qint64 readBytes = read(result.data(), result.size());
+
if (readBytes <= 0)
result.clear();
else