summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-06-17 12:51:45 +0200
committerMarc Mutz <marc.mutz@kdab.com>2015-06-19 16:30:03 +0000
commit9ab45763d7d5fddf54f373f3e2e19ddcb85e5144 (patch)
tree1b0e3843a3e57bbd7ade73d33328f4b78d6cd46e /src/network
parent855828978059bbc414f60f3f9eb5e06ea2c28ddc (diff)
downloadqtbase-9ab45763d7d5fddf54f373f3e2e19ddcb85e5144.tar.gz
QSpdyProtocolHandler: don't create QLists of key and value just to iterate over
Just iterate over the QMultiMap directly. Also, now that we use iterators, the remove operation becomes amortized O(1) instead of O(logN). The loop could be even O(N) (clean, not amortized) if QMap had range-erase. Change-Id: I0cf3511adc3a558e551ddd91e47dabcab376001a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/network')
-rw-r--r--src/network/access/qspdyprotocolhandler.cpp19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/network/access/qspdyprotocolhandler.cpp b/src/network/access/qspdyprotocolhandler.cpp
index 7430ca029d..7d2c0dfef2 100644
--- a/src/network/access/qspdyprotocolhandler.cpp
+++ b/src/network/access/qspdyprotocolhandler.cpp
@@ -288,16 +288,14 @@ bool QSpdyProtocolHandler::sendRequest()
m_channel->state = QHttpNetworkConnectionChannel::WritingState;
- // requests will be ordered by priority (see QMultiMap doc)
- QList<HttpMessagePair> requests = m_channel->spdyRequestsToSend.values();
- QList<int> priorities = m_channel->spdyRequestsToSend.keys();
-
- int requestsToSend = qMin(requests.count(), maxPossibleRequests);
+ int requestsToSend = qMin(m_channel->spdyRequestsToSend.size(), maxPossibleRequests);
+ QMultiMap<int, HttpMessagePair>::iterator it = m_channel->spdyRequestsToSend.begin();
+ // requests will be ordered by priority (see QMultiMap doc)
for (int a = 0; a < requestsToSend; ++a) {
- HttpMessagePair currentPair = requests.at(a);
- QHttpNetworkRequest currentRequest = requests.at(a).first;
- QHttpNetworkReply *currentReply = requests.at(a).second;
+ HttpMessagePair currentPair = *it;
+ QHttpNetworkRequest currentRequest = currentPair.first;
+ QHttpNetworkReply *currentReply = currentPair.second;
currentReply->setSpdyWasUsed(true);
qint32 streamID = generateNextStreamID();
@@ -310,10 +308,7 @@ bool QSpdyProtocolHandler::sendRequest()
connect(currentReply, SIGNAL(destroyed(QObject*)), this, SLOT(_q_replyDestroyed(QObject*)));
sendSYN_STREAM(currentPair, streamID, /* associatedToStreamID = */ 0);
- int requestsRemoved = m_channel->spdyRequestsToSend.remove(
- priorities.at(a), currentPair);
- Q_ASSERT(requestsRemoved == 1);
- Q_UNUSED(requestsRemoved); // silence -Wunused-variable
+ m_channel->spdyRequestsToSend.erase(it++);
}
m_channel->state = QHttpNetworkConnectionChannel::IdleState;
return true;