diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2017-11-08 17:18:57 +0200 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2017-11-09 15:31:34 +0200 |
commit | 7eea63dee1bc5afde06caddf43cff72150c0d351 (patch) | |
tree | 4338316a4a665ae0516b412998dba7032ab728a6 | |
parent | c229e2d3330999401244ed0fe4d180aa1cdc62bb (diff) | |
download | qtlocation-mapboxgl-7eea63dee1bc5afde06caddf43cff72150c0d351.tar.gz |
[Qt] Call QNetworkReply::readAll() only once
-rw-r--r-- | platform/qt/src/http_file_source.cpp | 3 | ||||
-rw-r--r-- | platform/qt/src/http_request.cpp | 7 | ||||
-rw-r--r-- | platform/qt/src/http_request.hpp | 2 |
3 files changed, 6 insertions, 6 deletions
diff --git a/platform/qt/src/http_file_source.cpp b/platform/qt/src/http_file_source.cpp index 573b707c27..6e70693241 100644 --- a/platform/qt/src/http_file_source.cpp +++ b/platform/qt/src/http_file_source.cpp @@ -80,9 +80,10 @@ void HTTPFileSource::Impl::onReplyFinished() return; } + QByteArray data = reply->readAll(); QVector<HTTPRequest*>& requestsVector = it.value().second; for (auto req : requestsVector) { - req->handleNetworkReply(reply); + req->handleNetworkReply(reply, data); } m_pending.erase(it); diff --git a/platform/qt/src/http_request.cpp b/platform/qt/src/http_request.cpp index 386a2d9ef4..ea3f388bd5 100644 --- a/platform/qt/src/http_request.cpp +++ b/platform/qt/src/http_request.cpp @@ -52,7 +52,7 @@ QNetworkRequest HTTPRequest::networkRequest() const return req; } -void HTTPRequest::handleNetworkReply(QNetworkReply *reply) +void HTTPRequest::handleNetworkReply(QNetworkReply *reply, const QByteArray& data) { m_handled = true; @@ -98,11 +98,10 @@ void HTTPRequest::handleNetworkReply(QNetworkReply *reply) switch(responseCode) { case 200: { - QByteArray bytes = reply->readAll(); - if (bytes.isEmpty()) { + if (data.isEmpty()) { response.data = std::make_shared<std::string>(); } else { - response.data = std::make_shared<std::string>(bytes.constData(), bytes.size()); + response.data = std::make_shared<std::string>(data.constData(), data.size()); } break; } diff --git a/platform/qt/src/http_request.hpp b/platform/qt/src/http_request.hpp index 959f97759a..b4d476d586 100644 --- a/platform/qt/src/http_request.hpp +++ b/platform/qt/src/http_request.hpp @@ -20,7 +20,7 @@ public: QUrl requestUrl() const; QNetworkRequest networkRequest() const; - void handleNetworkReply(QNetworkReply *); + void handleNetworkReply(QNetworkReply *, const QByteArray& data); private: HTTPFileSource::Impl* m_context; |