summaryrefslogtreecommitdiffstats
path: root/src/plugins/tls/openssl/qtlsbackend_openssl.cpp
diff options
context:
space:
mode:
authorAhmad Samir <[email protected]>2025-05-01 01:21:18 +0300
committerAhmad Samir <[email protected]>2025-05-14 04:41:13 +0300
commit6dcf1483940cb180cbe59e0ea8781d722ae6cddd (patch)
tree54815a04d82ccb8d9881d70bfe05186952e9fc39 /src/plugins/tls/openssl/qtlsbackend_openssl.cpp
parent4a3e7bb1fa90c95d67cd55a44d9b1ef23f3bdfaf (diff)
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 <[email protected]>
Diffstat (limited to 'src/plugins/tls/openssl/qtlsbackend_openssl.cpp')
-rw-r--r--src/plugins/tls/openssl/qtlsbackend_openssl.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/plugins/tls/openssl/qtlsbackend_openssl.cpp b/src/plugins/tls/openssl/qtlsbackend_openssl.cpp
index 15bf384ae86..6a55f275943 100644
--- a/src/plugins/tls/openssl/qtlsbackend_openssl.cpp
+++ b/src/plugins/tls/openssl/qtlsbackend_openssl.cpp
@@ -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))