From 3b57425aa11e5e1536016ccccdde7657493a0dc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Thu, 7 Jan 2010 13:31:08 +0100 Subject: 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 --- src/corelib/io/qfile.cpp | 7 +++---- 1 file 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()); -- cgit v0.12