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>
bb10
Marc Mutz 2015-06-17 12:51:45 +02:00
parent 8558289780
commit 9ab45763d7
1 changed files with 7 additions and 12 deletions

View File

@ -288,16 +288,14 @@ bool QSpdyProtocolHandler::sendRequest()
m_channel->state = QHttpNetworkConnectionChannel::WritingState;
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)
QList<HttpMessagePair> requests = m_channel->spdyRequestsToSend.values();
QList<int> priorities = m_channel->spdyRequestsToSend.keys();
int requestsToSend = qMin(requests.count(), maxPossibleRequests);
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;