qsslcertificate: use QStringView more
to avoid needless allocations Change-Id: I54d159cbaa0854355286c942a6971e45c4494a14 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
f5f78400e1
commit
576e7d49f5
@ -624,7 +624,7 @@ QList<QSslCertificate> QSslCertificate::fromPath(const QString &path,
|
|||||||
QString sourcePath = QDir::fromNativeSeparators(path);
|
QString sourcePath = QDir::fromNativeSeparators(path);
|
||||||
|
|
||||||
// Find the path without the filename
|
// 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
|
// Check if the path contains any special chars
|
||||||
int pos = -1;
|
int pos = -1;
|
||||||
@ -647,7 +647,7 @@ QList<QSslCertificate> QSslCertificate::fromPath(const QString &path,
|
|||||||
if (lastIndexOfSlash != -1)
|
if (lastIndexOfSlash != -1)
|
||||||
pathPrefix = pathPrefix.left(lastIndexOfSlash);
|
pathPrefix = pathPrefix.left(lastIndexOfSlash);
|
||||||
else
|
else
|
||||||
pathPrefix.clear();
|
pathPrefix = {};
|
||||||
} else {
|
} else {
|
||||||
// Check if the path is a file.
|
// Check if the path is a file.
|
||||||
if (QFileInfo(sourcePath).isFile()) {
|
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.
|
// Special case - if the prefix ends up being nothing, use "." instead.
|
||||||
int startIndex = 0;
|
int startIndex = 0;
|
||||||
if (pathPrefix.isEmpty()) {
|
if (pathPrefix.isEmpty()) {
|
||||||
pathPrefix = "."_L1;
|
pathPrefix = u".";
|
||||||
startIndex = 2;
|
startIndex = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QString pathPrefixString = pathPrefix.toString();
|
||||||
|
|
||||||
// The path can be a file or directory.
|
// The path can be a file or directory.
|
||||||
QList<QSslCertificate> certs;
|
QList<QSslCertificate> certs;
|
||||||
|
|
||||||
@ -678,7 +680,7 @@ QList<QSslCertificate> QSslCertificate::fromPath(const QString &path,
|
|||||||
QRegularExpression pattern(QRegularExpression::anchoredPattern(sourcePath));
|
QRegularExpression pattern(QRegularExpression::anchoredPattern(sourcePath));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QDirIterator it(pathPrefix, QDir::Files, QDirIterator::FollowSymlinks | QDirIterator::Subdirectories);
|
QDirIterator it(pathPrefixString, QDir::Files, QDirIterator::FollowSymlinks | QDirIterator::Subdirectories);
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
QString filePath = startIndex == 0 ? it.next() : it.next().mid(startIndex);
|
QString filePath = startIndex == 0 ? it.next() : it.next().mid(startIndex);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user