diff options
author | João Abecasis <joao@trolltech.com> | 2010-01-07 12:31:08 (GMT) |
---|---|---|
committer | João Abecasis <joao@trolltech.com> | 2010-01-07 15:33:26 (GMT) |
commit | 3b57425aa11e5e1536016ccccdde7657493a0dc8 (patch) | |
tree | de9b196b7971906c757641903f0ac250ef193687 /src/corelib/io/qfile.cpp | |
parent | ce5f772c529517c3e1c043fd826a790316ed9915 (diff) | |
download | Qt-3b57425aa11e5e1536016ccccdde7657493a0dc8.zip Qt-3b57425aa11e5e1536016ccccdde7657493a0dc8.tar.gz Qt-3b57425aa11e5e1536016ccccdde7657493a0dc8.tar.bz2 |
Avoid double-buffering in QFile
Since Qt 4.3 QIODevice has been providing read buffering for buffered
devices; QFile provides a write buffer. Thus, requesting a buffered file
from the engine results in unnecessary double-buffering where this is
supported natively.
By preferring QFile/QIODevice's buffering over the file engine we reduce
the number of system calls.
On the other hand, buffering inside QIODevice can't easily be disabled
without changing the return value of QIODevice::openMode() (function is
non-virtual).
Reviewed-by: Thiago Macieira
Diffstat (limited to 'src/corelib/io/qfile.cpp')
-rw-r--r-- | src/corelib/io/qfile.cpp | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp index 72d1d16..eb6f5be 100644 --- a/src/corelib/io/qfile.cpp +++ b/src/corelib/io/qfile.cpp @@ -968,9 +968,6 @@ bool QFile::isSequential() const mode, if the relevant file does not already exist, this function will try to create a new file before opening it. - \note Because of limitations in the native API, QFile ignores the - Unbuffered flag on Windows. - \sa QIODevice::OpenMode, setFileName() */ bool QFile::open(OpenMode mode) @@ -988,7 +985,9 @@ bool QFile::open(OpenMode mode) qWarning("QIODevice::open: File access not specified"); return false; } - if (fileEngine()->open(mode)) { + + // QIODevice provides the buffering, so there's no need to request it from the file engine. + if (fileEngine()->open(mode | QIODevice::Unbuffered)) { QIODevice::open(mode); if (mode & Append) seek(size()); |