diff options
author | Markus Goetz <Markus.Goetz@nokia.com> | 2009-06-25 14:52:45 (GMT) |
---|---|---|
committer | Markus Goetz <Markus.Goetz@nokia.com> | 2009-06-25 15:25:15 (GMT) |
commit | 3984253ac58e0cca1c0b94fad1549dd4e0e3c2e1 (patch) | |
tree | 98fdc5bf2e42626eb0cebcfb60c2a61a73b352c3 /src/network/access | |
parent | b393abc9ce2e2a5396e655895fe653f9e06e355f (diff) | |
download | Qt-3984253ac58e0cca1c0b94fad1549dd4e0e3c2e1.zip Qt-3984253ac58e0cca1c0b94fad1549dd4e0e3c2e1.tar.gz Qt-3984253ac58e0cca1c0b94fad1549dd4e0e3c2e1.tar.bz2 |
QNAM HTTP Code: Prepare for download performance improvements
Change the QByteArray to a QRingBuffer to save re-allocation time.
Reviewed-by: Thiago Macieira <thiago.macieira@nokia.com>
Diffstat (limited to 'src/network/access')
-rw-r--r-- | src/network/access/qhttpnetworkconnection.cpp | 20 | ||||
-rw-r--r-- | src/network/access/qhttpnetworkconnection_p.h | 1 | ||||
-rw-r--r-- | src/network/access/qhttpnetworkreply.cpp | 9 | ||||
-rw-r--r-- | src/network/access/qhttpnetworkreply_p.h | 6 |
4 files changed, 27 insertions, 9 deletions
diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index 365ae8b..8409660 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -176,7 +176,8 @@ bool QHttpNetworkConnectionPrivate::isSocketReading(QAbstractSocket *socket) con void QHttpNetworkConnectionPrivate::appendUncompressedData(QHttpNetworkReply &reply, const QByteArray &fragment) { - reply.d_func()->responseData.append(fragment); + char *dst = reply.d_func()->responseData.reserve(fragment.size()); + qMemCopy(dst, fragment.constData(), fragment.size()); } void QHttpNetworkConnectionPrivate::appendCompressedData(QHttpNetworkReply &reply, const QByteArray &fragment) @@ -189,6 +190,11 @@ qint64 QHttpNetworkConnectionPrivate::uncompressedBytesAvailable(const QHttpNetw return reply.d_func()->responseData.size(); } +qint64 QHttpNetworkConnectionPrivate::uncompressedBytesAvailableNextBlock(const QHttpNetworkReply &reply) const +{ + return reply.d_func()->responseData.nextDataBlockSize(); +} + qint64 QHttpNetworkConnectionPrivate::compressedBytesAvailable(const QHttpNetworkReply &reply) const { return reply.d_func()->compressedData.size(); @@ -196,15 +202,15 @@ qint64 QHttpNetworkConnectionPrivate::compressedBytesAvailable(const QHttpNetwor qint64 QHttpNetworkConnectionPrivate::read(QHttpNetworkReply &reply, QByteArray &data, qint64 maxSize) { - QByteArray *ba = &reply.d_func()->responseData; - if (maxSize == -1 || maxSize >= ba->size()) { + QRingBuffer *rb = &reply.d_func()->responseData; + if (maxSize == -1 || maxSize >= rb->size()) { // read the whole data - data = *ba; - ba->clear(); + data = rb->readAll(); + rb->clear(); } else { // read only the requested length - data = ba->mid(0, maxSize); - ba->remove(0, maxSize); + data.resize(maxSize); + rb->read(data.data(), maxSize); } return data.size(); } diff --git a/src/network/access/qhttpnetworkconnection_p.h b/src/network/access/qhttpnetworkconnection_p.h index bc4d948..3eb8ffe 100644 --- a/src/network/access/qhttpnetworkconnection_p.h +++ b/src/network/access/qhttpnetworkconnection_p.h @@ -258,6 +258,7 @@ public: void appendCompressedData(QHttpNetworkReply &reply, const QByteArray &fragment); qint64 uncompressedBytesAvailable(const QHttpNetworkReply &reply) const; + qint64 uncompressedBytesAvailableNextBlock(const QHttpNetworkReply &reply) const; qint64 compressedBytesAvailable(const QHttpNetworkReply &reply) const; qint64 read(QHttpNetworkReply &reply, QByteArray &data, qint64 maxSize); diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp index 47fb6d1..202bdea 100644 --- a/src/network/access/qhttpnetworkreply.cpp +++ b/src/network/access/qhttpnetworkreply.cpp @@ -167,6 +167,15 @@ qint64 QHttpNetworkReply::bytesAvailable() const return -1; } +qint64 QHttpNetworkReply::bytesAvailableNextBlock() const +{ + Q_D(const QHttpNetworkReply); + if (d->connection) + return d->connection->d_func()->uncompressedBytesAvailableNextBlock(*this); + else + return -1; +} + QByteArray QHttpNetworkReply::read(qint64 maxSize) { Q_D(QHttpNetworkReply); diff --git a/src/network/access/qhttpnetworkreply_p.h b/src/network/access/qhttpnetworkreply_p.h index 08bd886..69c9158 100644 --- a/src/network/access/qhttpnetworkreply_p.h +++ b/src/network/access/qhttpnetworkreply_p.h @@ -79,6 +79,7 @@ static const unsigned char gz_magic[2] = {0x1f, 0x8b}; // gzip magic header #include <private/qhttpnetworkheader_p.h> #include <private/qhttpnetworkrequest_p.h> #include <private/qauthenticator_p.h> +#include <private/qringbuffer_p.h> QT_BEGIN_NAMESPACE @@ -120,6 +121,7 @@ public: QString reasonPhrase() const; qint64 bytesAvailable() const; + qint64 bytesAvailableNextBlock() const; QByteArray read(qint64 maxSize = -1); bool isFinished() const; @@ -193,7 +195,7 @@ public: qint64 bodyLength; qint64 contentRead; qint64 totalProgress; - QByteArray fragment; + QByteArray fragment; // used for header, status, chunk header etc, not for reply data qint64 currentChunkSize; qint64 currentChunkRead; QPointer<QHttpNetworkConnection> connection; @@ -204,7 +206,7 @@ public: #endif bool autoDecompress; - QByteArray responseData; // uncompressed body + QRingBuffer responseData; // uncompressed body QByteArray compressedData; // compressed body (temporary) bool requestIsPrepared; }; |