QHttpNetworkConnection: optimize startNextRequest
Use QVLA instead of QQueue to avoid allocations and use QSpan to emulate queue behavior to avoid N^2 Change-Id: I333bc1af98a596fc041765996867a3d6449fcfde Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
d5d2688acb
commit
f1b74f7b58
@ -17,6 +17,8 @@
|
|||||||
#include <qbuffer.h>
|
#include <qbuffer.h>
|
||||||
#include <qpair.h>
|
#include <qpair.h>
|
||||||
#include <qdebug.h>
|
#include <qdebug.h>
|
||||||
|
#include <qspan.h>
|
||||||
|
#include <qvarlengtharray.h>
|
||||||
|
|
||||||
#ifndef QT_NO_SSL
|
#ifndef QT_NO_SSL
|
||||||
# include <private/qsslsocket_p.h>
|
# include <private/qsslsocket_p.h>
|
||||||
@ -1134,7 +1136,7 @@ void QHttpNetworkConnectionPrivate::_q_startNextRequest()
|
|||||||
if (neededOpenChannels <= 0)
|
if (neededOpenChannels <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QQueue<int> channelsToConnect;
|
QVarLengthArray<int> channelsToConnect;
|
||||||
|
|
||||||
// use previously used channels first
|
// use previously used channels first
|
||||||
for (int i = 0; i < activeChannelCount && neededOpenChannels > 0; ++i) {
|
for (int i = 0; i < activeChannelCount && neededOpenChannels > 0; ++i) {
|
||||||
@ -1150,7 +1152,7 @@ void QHttpNetworkConnectionPrivate::_q_startNextRequest()
|
|||||||
|
|
||||||
if (!channels[i].reply && !channels[i].isSocketBusy()
|
if (!channels[i].reply && !channels[i].isSocketBusy()
|
||||||
&& (channels[i].socket->state() == QAbstractSocket::UnconnectedState)) {
|
&& (channels[i].socket->state() == QAbstractSocket::UnconnectedState)) {
|
||||||
channelsToConnect.enqueue(i);
|
channelsToConnect.push_back(i);
|
||||||
neededOpenChannels--;
|
neededOpenChannels--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1160,12 +1162,14 @@ void QHttpNetworkConnectionPrivate::_q_startNextRequest()
|
|||||||
if (channels[i].socket)
|
if (channels[i].socket)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
channelsToConnect.enqueue(i);
|
channelsToConnect.push_back(i);
|
||||||
neededOpenChannels--;
|
neededOpenChannels--;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!channelsToConnect.isEmpty()) {
|
auto channelToConnectSpan = QSpan{channelsToConnect};
|
||||||
const int channel = channelsToConnect.dequeue();
|
while (!channelToConnectSpan.isEmpty()) {
|
||||||
|
const int channel = channelToConnectSpan.front();
|
||||||
|
channelToConnectSpan = channelToConnectSpan.sliced(1);
|
||||||
|
|
||||||
if (networkLayerState == IPv4)
|
if (networkLayerState == IPv4)
|
||||||
channels[channel].networkLayerPreference = QAbstractSocket::IPv4Protocol;
|
channels[channel].networkLayerPreference = QAbstractSocket::IPv4Protocol;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user