diff options
author | Alex Trotsenko <alex1973tr@gmail.com> | 2016-02-19 16:52:29 +0200 |
---|---|---|
committer | Alex Trotsenko <alex1973tr@gmail.com> | 2016-03-15 20:27:00 +0000 |
commit | 5dc13fe05e775d1621a5bfaa9e6a53c7ab82efee (patch) | |
tree | 73391628bf066c9e527170575becda098e935ea9 /src/corelib/io/qiodevice.cpp | |
parent | d1b09dba45c4b3ee0f31cd9bbf6941f17afd48f0 (diff) |
QIODevice: allow zero-copy in read()
Try to prevent the data from being copied, if we have a chunk with the
same size in the read buffer.
Task-number: QTBUG-19169
Change-Id: I2a9a5c88855988888b56d0ca69ec4e50b8e6ef98
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
Diffstat (limited to 'src/corelib/io/qiodevice.cpp')
-rw-r--r-- | src/corelib/io/qiodevice.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp index fd204b00de..ee004b4293 100644 --- a/src/corelib/io/qiodevice.cpp +++ b/src/corelib/io/qiodevice.cpp @@ -1148,13 +1148,24 @@ QByteArray QIODevice::read(qint64 maxSize) Q_D(QIODevice); QByteArray result; - CHECK_MAXLEN(read, result); - #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 + // 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); if (maxSize >= MaxByteArraySize) { checkWarnMessage(this, "read", "maxSize argument exceeds QByteArray size limit"); maxSize = MaxByteArraySize - 1; |