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>
This commit is contained in:
parent
f416561702
commit
8f92baf5c9
@ -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]));
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user