diff options
author | Anton Kudryavtsev <[email protected]> | 2023-09-06 17:50:11 +0300 |
---|---|---|
committer | Anton Kudryavtsev <[email protected]> | 2023-09-07 16:05:04 +0300 |
commit | 576e7d49f521e68243c491b694cbb6cd2ed111f5 (patch) | |
tree | 55cc725066fb5ee55133fda1a8f322ccd3db86a2 | |
parent | f5f78400e15e72bdb7ddda1d0a5623a80009b933 (diff) |
qsslcertificate: use QStringView more
to avoid needless allocations
Change-Id: I54d159cbaa0854355286c942a6971e45c4494a14
Reviewed-by: MÃ¥rten Nordheim <[email protected]>
-rw-r--r-- | src/network/ssl/qsslcertificate.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/network/ssl/qsslcertificate.cpp b/src/network/ssl/qsslcertificate.cpp index 56904006a6c..50fcb9032cb 100644 --- a/src/network/ssl/qsslcertificate.cpp +++ b/src/network/ssl/qsslcertificate.cpp @@ -624,7 +624,7 @@ QList<QSslCertificate> QSslCertificate::fromPath(const QString &path, QString sourcePath = QDir::fromNativeSeparators(path); // Find the path without the filename - QString pathPrefix = sourcePath.left(sourcePath.lastIndexOf(u'/')); + QStringView pathPrefix = QStringView(sourcePath).left(sourcePath.lastIndexOf(u'/')); // Check if the path contains any special chars int pos = -1; @@ -647,7 +647,7 @@ QList<QSslCertificate> QSslCertificate::fromPath(const QString &path, if (lastIndexOfSlash != -1) pathPrefix = pathPrefix.left(lastIndexOfSlash); else - pathPrefix.clear(); + pathPrefix = {}; } else { // Check if the path is a file. if (QFileInfo(sourcePath).isFile()) { @@ -664,10 +664,12 @@ QList<QSslCertificate> QSslCertificate::fromPath(const QString &path, // Special case - if the prefix ends up being nothing, use "." instead. int startIndex = 0; if (pathPrefix.isEmpty()) { - pathPrefix = "."_L1; + pathPrefix = u"."; startIndex = 2; } + const QString pathPrefixString = pathPrefix.toString(); + // The path can be a file or directory. QList<QSslCertificate> certs; @@ -678,7 +680,7 @@ QList<QSslCertificate> QSslCertificate::fromPath(const QString &path, QRegularExpression pattern(QRegularExpression::anchoredPattern(sourcePath)); #endif - QDirIterator it(pathPrefix, QDir::Files, QDirIterator::FollowSymlinks | QDirIterator::Subdirectories); + QDirIterator it(pathPrefixString, QDir::Files, QDirIterator::FollowSymlinks | QDirIterator::Subdirectories); while (it.hasNext()) { QString filePath = startIndex == 0 ? it.next() : it.next().mid(startIndex); |