summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Trotsenko <alex1973tr@gmail.com>2015-09-12 21:29:13 +0300
committerAlex Trotsenko <alex1973tr@gmail.com>2016-01-29 09:14:36 +0000
commit8f92baf5c946a93430e73adc79b4435060840777 (patch)
tree6ea19568c3f0707dbf392c4f321482f5da024ff9
parentf416561702e6162466ce23818a987db69a5053b5 (diff)
Adapt QFileDevice to use QIODevice's write buffer
Also, bump the TypeInformationVersion field in qtHookData, to notify the Qt Creator developers that the offset of QFilePrivate::fileName was changed and dumpers should be adapted. Change-Id: I71bc5f509b733c0ab3430cd47ff08961f0388839 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
-rw-r--r--src/corelib/global/qhooks.cpp2
-rw-r--r--src/corelib/io/qfiledevice.cpp31
-rw-r--r--src/corelib/io/qfiledevice_p.h2
-rw-r--r--tests/auto/other/toolsupport/tst_toolsupport.cpp2
4 files changed, 17 insertions, 20 deletions
diff --git a/src/corelib/global/qhooks.cpp b/src/corelib/global/qhooks.cpp
index 6549aebbbf..da401ffd78 100644
--- a/src/corelib/global/qhooks.cpp
+++ b/src/corelib/global/qhooks.cpp
@@ -67,7 +67,7 @@ quintptr Q_CORE_EXPORT qtHookData[] = {
// The required sizes and offsets are tested in tests/auto/other/toolsupport.
// When this fails and the change was intentional, adjust the test and
// adjust this value here.
- 3
+ 4
};
Q_STATIC_ASSERT(QHooks::LastHookIndex == sizeof(qtHookData) / sizeof(qtHookData[0]));
diff --git a/src/corelib/io/qfiledevice.cpp b/src/corelib/io/qfiledevice.cpp
index 8ea2206e6b..b712fb719f 100644
--- a/src/corelib/io/qfiledevice.cpp
+++ b/src/corelib/io/qfiledevice.cpp
@@ -48,13 +48,16 @@
QT_BEGIN_NAMESPACE
-static const int QFILE_WRITEBUFFER_SIZE = 16384;
+#ifndef QFILE_WRITEBUFFER_SIZE
+#define QFILE_WRITEBUFFER_SIZE 16384
+#endif
QFileDevicePrivate::QFileDevicePrivate()
: fileEngine(0),
- writeBuffer(QFILE_WRITEBUFFER_SIZE), cachedSize(0),
+ cachedSize(0),
error(QFile::NoError), lastWasWrite(false)
{
+ writeBufferChunkSize = QFILE_WRITEBUFFER_SIZE;
}
QFileDevicePrivate::~QFileDevicePrivate()
@@ -274,14 +277,6 @@ QString QFileDevice::fileName() const
return QString();
}
-static inline qint64 _qfile_writeData(QAbstractFileEngine *engine, QRingBuffer *buffer)
-{
- qint64 ret = engine->write(buffer->readPointer(), buffer->nextDataBlockSize());
- if (ret > 0)
- buffer->free(ret);
- return ret;
-}
-
/*!
Flushes any buffered data to the file. Returns \c true if successful;
otherwise returns \c false.
@@ -295,8 +290,11 @@ bool QFileDevice::flush()
}
if (!d->writeBuffer.isEmpty()) {
- qint64 size = d->writeBuffer.size();
- if (_qfile_writeData(d->fileEngine, &d->writeBuffer) != size) {
+ qint64 size = d->writeBuffer.nextDataBlockSize();
+ qint64 written = d->fileEngine->write(d->writeBuffer.readPointer(), size);
+ if (written > 0)
+ d->writeBuffer.free(written);
+ if (written != size) {
QFileDevice::FileError err = d->fileEngine->error();
if (err == QFileDevice::UnspecifiedError)
err = QFileDevice::WriteError;
@@ -488,9 +486,10 @@ bool QFileDevicePrivate::putCharHelper(char c)
// Cutoff for code that doesn't only touch the buffer.
qint64 writeBufferSize = writeBuffer.size();
- if ((openMode & QIODevice::Unbuffered) || writeBufferSize + 1 >= QFILE_WRITEBUFFER_SIZE
+ if ((openMode & QIODevice::Unbuffered) || writeBufferSize + 1 >= writeBufferChunkSize
#ifdef Q_OS_WIN
- || ((openMode & QIODevice::Text) && c == '\n' && writeBufferSize + 2 >= QFILE_WRITEBUFFER_SIZE)
+ || ((openMode & QIODevice::Text) && c == '\n'
+ && writeBufferSize + 2 >= writeBufferChunkSize)
#endif
) {
return QIODevicePrivate::putCharHelper(c);
@@ -544,14 +543,14 @@ qint64 QFileDevice::writeData(const char *data, qint64 len)
bool buffered = !(d->openMode & Unbuffered);
// Flush buffered data if this read will overflow.
- if (buffered && (d->writeBuffer.size() + len) > QFILE_WRITEBUFFER_SIZE) {
+ if (buffered && (d->writeBuffer.size() + len) > d->writeBufferChunkSize) {
if (!flush())
return -1;
}
// Write directly to the engine if the block size is larger than
// the write buffer size.
- if (!buffered || len > QFILE_WRITEBUFFER_SIZE) {
+ if (!buffered || len > d->writeBufferChunkSize) {
const qint64 ret = d->fileEngine->write(data, len);
if (ret < 0) {
QFileDevice::FileError err = d->fileEngine->error();
diff --git a/src/corelib/io/qfiledevice_p.h b/src/corelib/io/qfiledevice_p.h
index d3dcb34dd6..60c51afb7e 100644
--- a/src/corelib/io/qfiledevice_p.h
+++ b/src/corelib/io/qfiledevice_p.h
@@ -52,7 +52,6 @@
//
#include "private/qiodevice_p.h"
-#include "private/qringbuffer_p.h"
QT_BEGIN_NAMESPACE
@@ -77,7 +76,6 @@ protected:
void setError(QFileDevice::FileError err, int errNum);
mutable QAbstractFileEngine *fileEngine;
- QRingBuffer writeBuffer;
mutable qint64 cachedSize;
QFileDevice::FileHandleFlags handleFlags;
diff --git a/tests/auto/other/toolsupport/tst_toolsupport.cpp b/tests/auto/other/toolsupport/tst_toolsupport.cpp
index 12526fe647..7942a84615 100644
--- a/tests/auto/other/toolsupport/tst_toolsupport.cpp
+++ b/tests/auto/other/toolsupport/tst_toolsupport.cpp
@@ -124,7 +124,7 @@ void tst_toolsupport::offsets_data()
{
QTestData &data = QTest::newRow("QFilePrivate::fileName")
<< pmm_to_offsetof(&QFilePrivate::fileName);
- data << 196 << 280;
+ data << 168 << 248;
}
#endif