diff options
author | Markus Goetz <Markus.Goetz@nokia.com> | 2009-05-19 15:29:01 (GMT) |
---|---|---|
committer | Markus Goetz <Markus.Goetz@nokia.com> | 2009-05-20 06:48:24 (GMT) |
commit | 96fbcbfe543e609cc6c244f605c8b7c9b51be535 (patch) | |
tree | 848967efaf545fb70266cd8ef8298a2f7f080dcb | |
parent | ccca1883cf621eb78768962e9e6476ae0ce57a70 (diff) | |
download | Qt-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
-rw-r--r-- | src/corelib/io/qiodevice.cpp | 7 |
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. |