QtNetwork: use QStringRef to optimize memory allocation
Replace substring functions that return QString with corresponding functions that return QStringRef where it's possible. Create QString from QStringRef only where necessary. Change-Id: I697f776c60003629990cfd197534ffed63bafe2f Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
parent
5323ffed64
commit
3cbe25c9a6
@ -587,10 +587,10 @@ static void _q_parseDosDir(const QStringList &tokens, const QString &userName, Q
|
||||
int permissions = QUrlInfo::ReadOwner | QUrlInfo::WriteOwner
|
||||
| QUrlInfo::ReadGroup | QUrlInfo::WriteGroup
|
||||
| QUrlInfo::ReadOther | QUrlInfo::WriteOther;
|
||||
QString ext;
|
||||
QStringRef ext;
|
||||
int extIndex = name.lastIndexOf(QLatin1Char('.'));
|
||||
if (extIndex != -1)
|
||||
ext = name.mid(extIndex + 1);
|
||||
ext = name.midRef(extIndex + 1);
|
||||
if (ext == QLatin1String("exe") || ext == QLatin1String("bat") || ext == QLatin1String("com"))
|
||||
permissions |= QUrlInfo::ExeOwner | QUrlInfo::ExeGroup | QUrlInfo::ExeOther;
|
||||
info->setPermissions(permissions);
|
||||
@ -961,19 +961,19 @@ void QFtpPI::readyRead()
|
||||
endOfMultiLine[3] = QLatin1Char(' ');
|
||||
QString lineCont(endOfMultiLine);
|
||||
lineCont[3] = QLatin1Char('-');
|
||||
QString lineLeft4 = line.left(4);
|
||||
QStringRef lineLeft4 = line.leftRef(4);
|
||||
|
||||
while (lineLeft4 != endOfMultiLine) {
|
||||
if (lineLeft4 == lineCont)
|
||||
replyText += line.mid(4); // strip 'xyz-'
|
||||
replyText += line.midRef(4); // strip 'xyz-'
|
||||
else
|
||||
replyText += line;
|
||||
if (!commandSocket.canReadLine())
|
||||
return;
|
||||
line = QString::fromLatin1(commandSocket.readLine());
|
||||
lineLeft4 = line.left(4);
|
||||
lineLeft4 = line.leftRef(4);
|
||||
}
|
||||
replyText += line.mid(4); // strip reply code 'xyz '
|
||||
replyText += line.midRef(4); // strip reply code 'xyz '
|
||||
if (replyText.endsWith(QLatin1String("\r\n")))
|
||||
replyText.chop(2);
|
||||
|
||||
@ -1089,7 +1089,7 @@ bool QFtpPI::processReply()
|
||||
} else {
|
||||
++portPos;
|
||||
QChar delimiter = replyText.at(portPos);
|
||||
QStringList epsvParameters = replyText.mid(portPos).split(delimiter);
|
||||
const auto epsvParameters = replyText.midRef(portPos).split(delimiter);
|
||||
|
||||
waitForDtpToConnect = true;
|
||||
dtp.connectToHost(commandSocket.peerAddress().toString(),
|
||||
|
@ -1041,11 +1041,11 @@ QPair<QHostAddress, int> QHostAddress::parseSubnet(const QString &subnet)
|
||||
return invalid; // invalid netmask
|
||||
|
||||
// parse the address manually
|
||||
QStringList parts = netStr.split(QLatin1Char('.'));
|
||||
auto parts = netStr.splitRef(QLatin1Char('.'));
|
||||
if (parts.isEmpty() || parts.count() > 4)
|
||||
return invalid; // invalid IPv4 address
|
||||
|
||||
if (parts.last().isEmpty())
|
||||
if (parts.constLast().isEmpty())
|
||||
parts.removeLast();
|
||||
|
||||
quint32 addr = 0;
|
||||
|
@ -867,7 +867,7 @@ QSslCipher QSslSocketBackendPrivate::QSslCipher_from_SSLCipherSuite(SSLCipherSui
|
||||
ciph.d->protocolString = QLatin1String("TLSv1.2");
|
||||
}
|
||||
|
||||
const QStringList bits = ciph.d->name.split('-');
|
||||
const auto bits = ciph.d->name.splitRef(QLatin1Char('-'));
|
||||
if (bits.size() >= 2) {
|
||||
if (bits.size() == 2 || bits.size() == 3) {
|
||||
ciph.d->keyExchangeMethod = QLatin1String("RSA");
|
||||
|
@ -226,13 +226,13 @@ QSslCipher QSslSocketBackendPrivate::QSslCipher_from_SSL_CIPHER(SSL_CIPHER *ciph
|
||||
char buf [256];
|
||||
QString descriptionOneLine = QString::fromLatin1(q_SSL_CIPHER_description(cipher, buf, sizeof(buf)));
|
||||
|
||||
QStringList descriptionList = descriptionOneLine.split(QLatin1Char(' '), QString::SkipEmptyParts);
|
||||
const auto descriptionList = descriptionOneLine.splitRef(QLatin1Char(' '), QString::SkipEmptyParts);
|
||||
if (descriptionList.size() > 5) {
|
||||
// ### crude code.
|
||||
ciph.d->isNull = false;
|
||||
ciph.d->name = descriptionList.at(0);
|
||||
ciph.d->name = descriptionList.at(0).toString();
|
||||
|
||||
QString protoString = descriptionList.at(1);
|
||||
QString protoString = descriptionList.at(1).toString();
|
||||
ciph.d->protocolString = protoString;
|
||||
ciph.d->protocol = QSsl::UnknownProtocol;
|
||||
if (protoString == QLatin1String("SSLv3"))
|
||||
@ -247,11 +247,11 @@ QSslCipher QSslSocketBackendPrivate::QSslCipher_from_SSL_CIPHER(SSL_CIPHER *ciph
|
||||
ciph.d->protocol = QSsl::TlsV1_2;
|
||||
|
||||
if (descriptionList.at(2).startsWith(QLatin1String("Kx=")))
|
||||
ciph.d->keyExchangeMethod = descriptionList.at(2).mid(3);
|
||||
ciph.d->keyExchangeMethod = descriptionList.at(2).mid(3).toString();
|
||||
if (descriptionList.at(3).startsWith(QLatin1String("Au=")))
|
||||
ciph.d->authenticationMethod = descriptionList.at(3).mid(3);
|
||||
ciph.d->authenticationMethod = descriptionList.at(3).mid(3).toString();
|
||||
if (descriptionList.at(4).startsWith(QLatin1String("Enc=")))
|
||||
ciph.d->encryptionMethod = descriptionList.at(4).mid(4);
|
||||
ciph.d->encryptionMethod = descriptionList.at(4).mid(4).toString();
|
||||
ciph.d->exportable = (descriptionList.size() > 6 && descriptionList.at(6) == QLatin1String("export"));
|
||||
|
||||
ciph.d->bits = q_SSL_CIPHER_get_bits(cipher, &ciph.d->supportedBits);
|
||||
|
Loading…
Reference in New Issue
Block a user