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 <rich@kde.org>
This commit is contained in:
Marc Mutz 2015-07-12 00:49:02 +02:00
parent 639ef6ca1a
commit a545715c83

View File

@ -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 findAllLibSsl()
{
return findAllLibs(QLatin1String("libssl.*"));
}
static QStringList findAllLibCrypto()
{
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 foundCryptos;
return findAllLibs(QLatin1String("libcrypto.*"));
}
# endif