summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qiodevice.cpp
diff options
context:
space:
mode:
authorMarkus Goetz <Markus.Goetz@nokia.com>2010-01-04 16:16:07 (GMT)
committerMarkus Goetz <Markus.Goetz@nokia.com>2010-01-05 12:14:06 (GMT)
commitd03475b69aa552a490e32fb2b7ad4dfaeacecf93 (patch)
treeaa28da661b7cafb23f898180e2d699dbdba7712d /src/corelib/io/qiodevice.cpp
parent190f45bcc7383bdc68a904e7dd5780372d00afba (diff)
downloadQt-d03475b69aa552a490e32fb2b7ad4dfaeacecf93.zip
Qt-d03475b69aa552a490e32fb2b7ad4dfaeacecf93.tar.gz
Qt-d03475b69aa552a490e32fb2b7ad4dfaeacecf93.tar.bz2
Small optimization in QIODevice::readAll()
.. and more testcases Reviewed-by: joao
Diffstat (limited to 'src/corelib/io/qiodevice.cpp')
-rw-r--r--src/corelib/io/qiodevice.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp
index 0e5a2de..8dcccb4 100644
--- a/src/corelib/io/qiodevice.cpp
+++ b/src/corelib/io/qiodevice.cpp
@@ -965,7 +965,15 @@ QByteArray QIODevice::readAll()
QByteArray result;
qint64 readBytes = 0;
- if (d->isSequential() || (readBytes = size()) == 0) {
+
+ // flush internal read buffer
+ if (!(d->openMode & Text) && !d->buffer.isEmpty()) {
+ result = d->buffer.readAll();
+ readBytes = result.size();
+ }
+
+ qint64 theSize;
+ if (d->isSequential() || (theSize = size()) == 0) {
// Size is unknown, read incrementally.
qint64 readResult;
do {
@@ -977,7 +985,7 @@ QByteArray QIODevice::readAll()
} else {
// Read it all in one go.
// If resize fails, don't read anything.
- result.resize(int(readBytes - d->pos));
+ result.resize(int(theSize - d->pos));
readBytes = read(result.data(), result.size());
}