diff options
author | Alex Trotsenko <alex1973tr@gmail.com> | 2014-10-08 17:34:33 +0300 |
---|---|---|
committer | Alex Trotsenko <alex1973tr@gmail.com> | 2015-01-20 10:37:59 +0100 |
commit | a373ffcda9b2e7b38509dcb2e772b86d67a72c80 (patch) | |
tree | 6b0cc986d29c574ec19ba4f2416e20ea14c9d4d6 /src/corelib | |
parent | bdcb3f9aab139e31849aec46088dce52ba7673eb (diff) |
QIODevice: remove ineffective caching members
Most of the QIODevice functions already have a locally cached
"sequential" flag. Make the rest of them follow this strategy.
This eliminates the need to use private caching members.
Change-Id: I0edb2c9b7c5f411c5bee25c425e7b40e3c9021d3
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: hjk <hjk@theqtcompany.com>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/global/qhooks.cpp | 2 | ||||
-rw-r--r-- | src/corelib/io/qiodevice.cpp | 33 | ||||
-rw-r--r-- | src/corelib/io/qiodevice_p.h | 4 |
3 files changed, 19 insertions, 20 deletions
diff --git a/src/corelib/global/qhooks.cpp b/src/corelib/global/qhooks.cpp index 7638414cf1..39ed87e789 100644 --- a/src/corelib/global/qhooks.cpp +++ b/src/corelib/global/qhooks.cpp @@ -37,7 +37,7 @@ QT_BEGIN_NAMESPACE // Only add to the end, and bump version if you do. quintptr Q_CORE_EXPORT qtHookData[] = { - 1, // hook data version + 2, // hook data version QHooks::LastHookIndex, // size of qtHookData QT_VERSION, diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp index b1f164ab1b..388c623bcb 100644 --- a/src/corelib/io/qiodevice.cpp +++ b/src/corelib/io/qiodevice.cpp @@ -117,8 +117,7 @@ void debugBinaryString(const char *data, qint64 maxlen) */ QIODevicePrivate::QIODevicePrivate() : openMode(QIODevice::NotOpen), buffer(QIODEVICE_BUFFERSIZE), - pos(0), devicePos(0), seqDumpPos(0) - , pPos(&pos), pDevicePos(&devicePos) + pos(0), devicePos(0) , baseReadLineDataCalled(false) , firstRead(true) , accessMode(Unset) @@ -566,7 +565,6 @@ void QIODevice::close() d->openMode = NotOpen; d->errorString.clear(); d->pos = 0; - d->seqDumpPos = 0; d->buffer.clear(); d->firstRead = true; } @@ -755,11 +753,14 @@ qint64 QIODevice::read(char *data, qint64 maxSize) this, data, int(maxSize), int(d->pos), int(d->buffer.size())); #endif + const bool sequential = d->isSequential(); + // Short circuit for getChar() if (maxSize == 1) { int chint; while ((chint = d->buffer.getChar()) != -1) { - ++(*d->pPos); + if (!sequential) + ++d->pos; char c = char(uchar(chint)); if (c == '\r' && (d->openMode & Text)) @@ -784,7 +785,8 @@ qint64 QIODevice::read(char *data, qint64 maxSize) // Try reading from the buffer. qint64 bufferReadChunkSize = d->buffer.read(data, maxSize); if (bufferReadChunkSize > 0) { - *d->pPos += bufferReadChunkSize; + if (!sequential) + d->pos += bufferReadChunkSize; readSoFar += bufferReadChunkSize; data += bufferReadChunkSize; maxSize -= bufferReadChunkSize; @@ -798,17 +800,13 @@ qint64 QIODevice::read(char *data, qint64 maxSize) // for fast pos updates. CHECK_READABLE(read, qint64(-1)); d->firstRead = false; - if (d->isSequential()) { - d->pPos = &d->seqDumpPos; - d->pDevicePos = &d->seqDumpPos; - } } } if (maxSize > 0 && !deviceAtEof) { qint64 readFromDevice = 0; // Make sure the device is positioned correctly. - if (d->pos == d->devicePos || d->isSequential() || seek(d->pos)) { + if (sequential || d->pos == d->devicePos || seek(d->pos)) { madeBufferReadsOnly = false; // fix readData attempt if (maxSize >= QIODEVICE_BUFFERSIZE || (d->openMode & Unbuffered)) { // Read big chunk directly to output buffer @@ -822,8 +820,10 @@ qint64 QIODevice::read(char *data, qint64 maxSize) readSoFar += readFromDevice; data += readFromDevice; maxSize -= readFromDevice; - *d->pPos += readFromDevice; - *d->pDevicePos += readFromDevice; + if (!sequential) { + d->pos += readFromDevice; + d->devicePos += readFromDevice; + } } } else { const int bytesToBuffer = QIODEVICE_BUFFERSIZE; @@ -832,7 +832,8 @@ qint64 QIODevice::read(char *data, qint64 maxSize) deviceAtEof = (readFromDevice != bytesToBuffer); d->buffer.chop(bytesToBuffer - qMax(0, int(readFromDevice))); if (readFromDevice > 0) { - *d->pDevicePos += readFromDevice; + if (!sequential) + d->devicePos += readFromDevice; #if defined QIODEVICE_DEBUG printf("%p \treading %d from device into buffer\n", this, int(readFromDevice)); @@ -1414,7 +1415,8 @@ qint64 QIODevicePrivate::peek(char *data, qint64 maxSize) return readBytes; buffer.ungetBlock(data, readBytes); - *pPos -= readBytes; + if (!isSequential()) + pos -= readBytes; return readBytes; } @@ -1429,7 +1431,8 @@ QByteArray QIODevicePrivate::peek(qint64 maxSize) return result; buffer.ungetBlock(result.constData(), result.size()); - *pPos -= result.size(); + if (!isSequential()) + pos -= result.size(); return result; } diff --git a/src/corelib/io/qiodevice_p.h b/src/corelib/io/qiodevice_p.h index d764cb0fbb..ac76f8ded8 100644 --- a/src/corelib/io/qiodevice_p.h +++ b/src/corelib/io/qiodevice_p.h @@ -209,10 +209,6 @@ public: QIODevicePrivateLinearBuffer buffer; qint64 pos; qint64 devicePos; - // these three are for fast position updates during read, avoiding isSequential test - qint64 seqDumpPos; - qint64 *pPos; - qint64 *pDevicePos; bool baseReadLineDataCalled; bool firstRead; |