remove redundant QIODevicePrivate member

QFile already caches if the fd is sequential in the metadata. QProcess,
QAbstractSocket and other classes simply return true from reimplementation
of QIODevice::isSequential()

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-05-27 08:08:16 +03:00
parent 0cc6689f84
commit 8507babac8
2 changed files with 13 additions and 29 deletions

View file

@ -100,9 +100,8 @@ inline void debugBinaryString(const char *data, qint64 maxlen)
*/ */
QIODevicePrivate::QIODevicePrivate() QIODevicePrivate::QIODevicePrivate()
: openMode(QIODevice::NotOpen), buffer(QIODEVICE_BUFFERSIZE), : openMode(QIODevice::NotOpen), buffer(QIODEVICE_BUFFERSIZE),
pos(0), devicePos(0) pos(0), devicePos(0),
, baseReadLineDataCalled(false) baseReadLineDataCalled(false)
, accessMode(Unset)
#ifdef QT_NO_QOBJECT #ifdef QT_NO_QOBJECT
, q_ptr(0) , q_ptr(0)
#endif #endif
@ -441,7 +440,6 @@ void QIODevice::setOpenMode(OpenMode openMode)
printf("%p QIODevice::setOpenMode(0x%x)\n", this, int(openMode)); printf("%p QIODevice::setOpenMode(0x%x)\n", this, int(openMode));
#endif #endif
d->openMode = openMode; d->openMode = openMode;
d->accessMode = QIODevicePrivate::Unset;
if (!isReadable()) if (!isReadable())
d->buffer.clear(); d->buffer.clear();
} }
@ -532,7 +530,6 @@ bool QIODevice::open(OpenMode mode)
d->openMode = mode; d->openMode = mode;
d->pos = (mode & Append) ? size() : qint64(0); d->pos = (mode & Append) ? size() : qint64(0);
d->buffer.clear(); d->buffer.clear();
d->accessMode = QIODevicePrivate::Unset;
#if defined QIODEVICE_DEBUG #if defined QIODEVICE_DEBUG
printf("%p QIODevice::open(0x%x)\n", this, quint32(mode)); printf("%p QIODevice::open(0x%x)\n", this, quint32(mode));
#endif #endif
@ -597,7 +594,7 @@ qint64 QIODevice::pos() const
*/ */
qint64 QIODevice::size() const qint64 QIODevice::size() const
{ {
return d_func()->isSequential() ? bytesAvailable() : qint64(0); return isSequential() ? bytesAvailable() : qint64(0);
} }
/*! /*!
@ -615,7 +612,7 @@ qint64 QIODevice::size() const
bool QIODevice::seek(qint64 pos) bool QIODevice::seek(qint64 pos)
{ {
Q_D(QIODevice); Q_D(QIODevice);
if (Q_UNLIKELY(d->isSequential())) { if (Q_UNLIKELY(isSequential())) {
qWarning("QIODevice::seek: Cannot call seek on a sequential device"); qWarning("QIODevice::seek: Cannot call seek on a sequential device");
return false; return false;
} else if (Q_UNLIKELY(d->openMode == NotOpen)) { } else if (Q_UNLIKELY(d->openMode == NotOpen)) {
@ -708,7 +705,7 @@ bool QIODevice::reset()
qint64 QIODevice::bytesAvailable() const qint64 QIODevice::bytesAvailable() const
{ {
Q_D(const QIODevice); Q_D(const QIODevice);
if (!d->isSequential()) if (!isSequential())
return qMax(size() - d->pos, qint64(0)); return qMax(size() - d->pos, qint64(0));
return d->buffer.size(); return d->buffer.size();
} }
@ -747,7 +744,7 @@ qint64 QIODevice::read(char *data, qint64 maxSize)
this, data, maxSize, d->pos, d->buffer.size()); this, data, maxSize, d->pos, d->buffer.size());
#endif #endif
const bool sequential = d->isSequential(); const bool sequential = isSequential();
// Short circuit for getChar() // Short circuit for getChar()
if (maxSize == 1) { if (maxSize == 1) {
@ -942,7 +939,7 @@ QByteArray QIODevice::readAll()
QByteArray result; QByteArray result;
qint64 readBytes = 0; qint64 readBytes = 0;
const bool sequential = d->isSequential(); const bool sequential = isSequential();
// flush internal read buffer // flush internal read buffer
if (!(d->openMode & Text) && !d->buffer.isEmpty()) { if (!(d->openMode & Text) && !d->buffer.isEmpty()) {
@ -1037,7 +1034,7 @@ qint64 QIODevice::readLine(char *data, qint64 maxSize)
// Leave room for a '\0' // Leave room for a '\0'
--maxSize; --maxSize;
const bool sequential = d->isSequential(); const bool sequential = isSequential();
qint64 readSoFar = 0; qint64 readSoFar = 0;
if (!d->buffer.isEmpty()) { if (!d->buffer.isEmpty()) {
@ -1239,7 +1236,7 @@ qint64 QIODevice::write(const char *data, qint64 maxSize)
CHECK_WRITABLE(write, qint64(-1)); CHECK_WRITABLE(write, qint64(-1));
CHECK_MAXLEN(write, qint64(-1)); CHECK_MAXLEN(write, qint64(-1));
const bool sequential = d->isSequential(); const bool sequential = isSequential();
// Make sure the device is positioned correctly. // Make sure the device is positioned correctly.
if (d->pos != d->devicePos && !sequential && !seek(d->pos)) if (d->pos != d->devicePos && !sequential && !seek(d->pos))
return qint64(-1); return qint64(-1);
@ -1306,7 +1303,7 @@ void QIODevice::ungetChar(char c)
#endif #endif
d->buffer.ungetChar(c); d->buffer.ungetChar(c);
if (!d->isSequential()) if (!isSequential())
--d->pos; --d->pos;
} }
@ -1332,7 +1329,7 @@ qint64 QIODevicePrivate::peek(char *data, qint64 maxSize)
return readBytes; return readBytes;
buffer.ungetBlock(data, readBytes); buffer.ungetBlock(data, readBytes);
if (!isSequential()) if (!q_func()->isSequential())
pos -= readBytes; pos -= readBytes;
return readBytes; return readBytes;
} }
@ -1348,7 +1345,7 @@ QByteArray QIODevicePrivate::peek(qint64 maxSize)
return result; return result;
buffer.ungetBlock(result.constData(), result.size()); buffer.ungetBlock(result.constData(), result.size());
if (!isSequential()) if (!q_func()->isSequential())
pos -= result.size(); pos -= result.size();
return result; return result;
} }

View file

@ -194,19 +194,6 @@ public:
qint64 devicePos; qint64 devicePos;
bool baseReadLineDataCalled; bool baseReadLineDataCalled;
enum AccessMode {
Unset,
Sequential,
RandomAccess
};
mutable AccessMode accessMode;
inline bool isSequential() const
{
if (accessMode == Unset)
accessMode = q_func()->isSequential() ? Sequential : RandomAccess;
return accessMode == Sequential;
}
virtual qint64 peek(char *data, qint64 maxSize); virtual qint64 peek(char *data, qint64 maxSize);
virtual QByteArray peek(qint64 maxSize); virtual QByteArray peek(qint64 maxSize);