qtlsbackend_openssl: optimize QDirListing usage
Internally QDirListing uses the name filters to create QRegularExpression objects which are then used to do the matching. Here we are looking for files that have ".pem" or ".crt" extensions, so basic string matching should work the same and is inherently faster. Change-Id: Ib19b1eb8717b21c3b96a52e7036665c40fb24caf Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> (cherry picked from commit 6dcf1483940cb180cbe59e0ea8781d722ae6cddd) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
6d179ef831
commit
ee39a89864
@ -391,13 +391,22 @@ QList<QSslCertificate> systemCaCertificates()
|
|||||||
QStringLiteral("/etc/pki/tls/certs/ca-bundle.crt"), // Fedora, Mandriva
|
QStringLiteral("/etc/pki/tls/certs/ca-bundle.crt"), // Fedora, Mandriva
|
||||||
QStringLiteral("/usr/local/share/certs/ca-root-nss.crt") // FreeBSD's ca_root_nss
|
QStringLiteral("/usr/local/share/certs/ca-root-nss.crt") // FreeBSD's ca_root_nss
|
||||||
};
|
};
|
||||||
static const QStringList nameFilters = {u"*.pem"_s, u"*.crt"_s};
|
|
||||||
|
static const size_t extLen = strlen(".pem"); // or strlen(".crt")
|
||||||
|
auto hasMatchingExtension = [](const QString &fileName) {
|
||||||
|
if (size_t(fileName.size()) < extLen + 1)
|
||||||
|
return false;
|
||||||
|
auto ext = QStringView{fileName}.last(extLen);
|
||||||
|
return ext == ".pem"_L1 || ext == ".crt"_L1;
|
||||||
|
};
|
||||||
|
|
||||||
using F = QDirListing::IteratorFlag;
|
using F = QDirListing::IteratorFlag;
|
||||||
constexpr auto flags = F::FilesOnly | F::ResolveSymlinks; // Files and symlinks to files
|
constexpr auto flags = F::FilesOnly | F::ResolveSymlinks; // Files and symlinks to files
|
||||||
for (const QByteArray &directory : directories) {
|
for (const QByteArray &directory : directories) {
|
||||||
for (const auto &dirEntry : QDirListing(QFile::decodeName(directory), nameFilters, flags)) {
|
for (const auto &dirEntry : QDirListing(QFile::decodeName(directory), flags)) {
|
||||||
// use canonical path here to not load the same certificate twice if symlinked
|
// use canonical path here to not load the same certificate twice if symlinked
|
||||||
certFiles.insert(dirEntry.canonicalFilePath());
|
if (hasMatchingExtension(dirEntry.fileName()))
|
||||||
|
certFiles.insert(dirEntry.canonicalFilePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (const QString& file : std::as_const(certFiles))
|
for (const QString& file : std::as_const(certFiles))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user