From 576e7d49f521e68243c491b694cbb6cd2ed111f5 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Wed, 6 Sep 2023 17:50:11 +0300 Subject: [PATCH] qsslcertificate: use QStringView more MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit to avoid needless allocations Change-Id: I54d159cbaa0854355286c942a6971e45c4494a14 Reviewed-by: MÃ¥rten Nordheim --- src/network/ssl/qsslcertificate.cpp | 10 ++++++---- 1 file 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::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::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::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 certs; @@ -678,7 +680,7 @@ QList 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);