summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qiodevice.cpp
diff options
context:
space:
mode:
authorMarkus Goetz <Markus.Goetz@nokia.com>2009-05-19 15:29:01 (GMT)
committerMarkus Goetz <Markus.Goetz@nokia.com>2009-05-20 06:48:24 (GMT)
commit96fbcbfe543e609cc6c244f605c8b7c9b51be535 (patch)
tree848967efaf545fb70266cd8ef8298a2f7f080dcb /src/corelib/io/qiodevice.cpp
parentccca1883cf621eb78768962e9e6476ae0ce57a70 (diff)
downloadQt-96fbcbfe543e609cc6c244f605c8b7c9b51be535.zip
Qt-96fbcbfe543e609cc6c244f605c8b7c9b51be535.tar.gz
Qt-96fbcbfe543e609cc6c244f605c8b7c9b51be535.tar.bz2
Optimize QIoDevice::readAll() to possibly do less (re)allocations
Reviewed-by: Olivier Goffart Reviewed-by: Peter Hartmann Reviewed-by: João Abecasis
Diffstat (limited to 'src/corelib/io/qiodevice.cpp')
-rw-r--r--src/corelib/io/qiodevice.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp
index c739054..efa4b25 100644
--- a/src/corelib/io/qiodevice.cpp
+++ b/src/corelib/io/qiodevice.cpp
@@ -945,9 +945,9 @@ QByteArray QIODevice::readAll()
QByteArray tmp;
if (d->isSequential() || size() == 0) {
- // Read it in chunks, bytesAvailable() is unreliable for sequential
- // devices.
- const int chunkSize = 4096;
+ // Read it in chunks. Use bytesAvailable() as an unreliable hint for
+ // sequential devices, but try to read 4K as a minimum.
+ int chunkSize = qMax(qint64(4096), bytesAvailable());
qint64 totalRead = 0;
forever {
tmp.resize(tmp.size() + chunkSize);
@@ -956,6 +956,7 @@ QByteArray QIODevice::readAll()
if (readBytes <= 0)
return tmp;
totalRead += readBytes;
+ chunkSize = qMax(qint64(4096), bytesAvailable());
}
} else {
// Read it all in one go.