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. Pick-to: 6.9 Change-Id: Ib19b1eb8717b21c3b96a52e7036665c40fb24caf Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
4a3e7bb1fa
commit
6dcf148394
@ -391,13 +391,22 @@ QList<QSslCertificate> systemCaCertificates()
|
||||
QStringLiteral("/etc/pki/tls/certs/ca-bundle.crt"), // Fedora, Mandriva
|
||||
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;
|
||||
constexpr auto flags = F::FilesOnly | F::ResolveSymlinks; // Files and symlinks to files
|
||||
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
|
||||
certFiles.insert(dirEntry.canonicalFilePath());
|
||||
if (hasMatchingExtension(dirEntry.fileName()))
|
||||
certFiles.insert(dirEntry.canonicalFilePath());
|
||||
}
|
||||
}
|
||||
for (const QString& file : std::as_const(certFiles))
|
||||
|
Loading…
x
Reference in New Issue
Block a user