From a545715c8317f79699610a58e15f4c48e9c1501e Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 12 Jul 2015 00:49:02 +0200 Subject: QSslSocket: remove code duplication Since findAllLibSsl() and findAllLibCrypto() differ only in the filter passed to QDir::entryList(), so Extract Method findAllLibs(). In the new function, cache the filters QStringList instead of re-create it in every loop iteration. Change-Id: I1bdd05e83fa1f9bb3f47b9b2ae5da9654ec1525b Reviewed-by: Richard J. Moore --- src/network/ssl/qsslsocket_openssl_symbols.cpp | 32 +++++++++++--------------- 1 file changed, 13 insertions(+), 19 deletions(-) (limited to 'src/network/ssl') diff --git a/src/network/ssl/qsslsocket_openssl_symbols.cpp b/src/network/ssl/qsslsocket_openssl_symbols.cpp index f9a9d22781..f12d2ab798 100644 --- a/src/network/ssl/qsslsocket_openssl_symbols.cpp +++ b/src/network/ssl/qsslsocket_openssl_symbols.cpp @@ -531,39 +531,33 @@ static QStringList libraryPathList() return paths; } - -static QStringList findAllLibSsl() +Q_NEVER_INLINE +static QStringList findAllLibs(QLatin1String filter) { QStringList paths = libraryPathList(); - QStringList foundSsls; + QStringList found; + const QStringList filters((QString(filter))); foreach (const QString &path, paths) { QDir dir(path); - QStringList entryList = dir.entryList(QStringList() << QLatin1String("libssl.*"), QDir::Files); + QStringList entryList = dir.entryList(filters, QDir::Files); std::sort(entryList.begin(), entryList.end(), LibGreaterThan()); foreach (const QString &entry, entryList) - foundSsls << path + QLatin1Char('/') + entry; + found << path + QLatin1Char('/') + entry; } - return foundSsls; + return found; } -static QStringList findAllLibCrypto() +static QStringList findAllLibSsl() { - QStringList paths = libraryPathList(); - - QStringList foundCryptos; - foreach (const QString &path, paths) { - QDir dir(path); - QStringList entryList = dir.entryList(QStringList() << QLatin1String("libcrypto.*"), QDir::Files); - - std::sort(entryList.begin(), entryList.end(), LibGreaterThan()); - foreach (const QString &entry, entryList) - foundCryptos << path + QLatin1Char('/') + entry; - } + return findAllLibs(QLatin1String("libssl.*")); +} - return foundCryptos; +static QStringList findAllLibCrypto() +{ + return findAllLibs(QLatin1String("libcrypto.*")); } # endif -- cgit v1.2.3