summaryrefslogtreecommitdiffstats
path: root/src/network/ssl
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2014-08-17 16:42:04 +0200
committerMarc Mutz <marc.mutz@kdab.com>2015-07-13 10:38:25 +0000
commited7f5375e115847cf8049bbed09c9ad06d510161 (patch)
treea19c6d519d9e55cefbe34f4820d4040c241feb63 /src/network/ssl
parent35eb5c86785fb30eeb5555355062ce29f84d0e84 (diff)
QSslSocket: use function objects and algorithms when sorting library paths
The first change is to make libGreaterThan a function object. This allows all compilers to inline the comparison into the sort implementation. The second change is to use QString::splitRef instead of QString::split to extract the components. The third is to extract the element comparison into a function object and replace the rest of libGreaterThan with a suitable call to std::lexicographical_compare, rendering most code comments (present or missing) moot. Change-Id: I3a761d721aa7cf5fa727dcc4ddca4b922f413899 Reviewed-by: Richard J. Moore <rich@kde.org>
Diffstat (limited to 'src/network/ssl')
-rw-r--r--src/network/ssl/qsslsocket_openssl_symbols.cpp50
1 files changed, 26 insertions, 24 deletions
diff --git a/src/network/ssl/qsslsocket_openssl_symbols.cpp b/src/network/ssl/qsslsocket_openssl_symbols.cpp
index 042c593e62..f9a9d22781 100644
--- a/src/network/ssl/qsslsocket_openssl_symbols.cpp
+++ b/src/network/ssl/qsslsocket_openssl_symbols.cpp
@@ -443,39 +443,41 @@ bool q_resolveOpenSslSymbols()
#else
# ifdef Q_OS_UNIX
-static bool libGreaterThan(const QString &lhs, const QString &rhs)
+struct NumericallyLess
{
- QStringList lhsparts = lhs.split(QLatin1Char('.'));
- QStringList rhsparts = rhs.split(QLatin1Char('.'));
- Q_ASSERT(lhsparts.count() > 1 && rhsparts.count() > 1);
-
- for (int i = 1; i < rhsparts.count(); ++i) {
- if (lhsparts.count() <= i)
- // left hand side is shorter, so it's less than rhs
- return false;
-
+ typedef bool result_type;
+ result_type operator()(const QStringRef &lhs, const QStringRef &rhs) const
+ {
bool ok = false;
int b = 0;
- int a = lhsparts.at(i).toInt(&ok);
+ int a = lhs.toInt(&ok);
if (ok)
- b = rhsparts.at(i).toInt(&ok);
+ b = rhs.toInt(&ok);
if (ok) {
// both toInt succeeded
- if (a == b)
- continue;
- return a > b;
+ return a < b;
} else {
// compare as strings;
- if (lhsparts.at(i) == rhsparts.at(i))
- continue;
- return lhsparts.at(i) > rhsparts.at(i);
+ return lhs < rhs;
}
}
+};
- // they compared strictly equally so far
- // lhs cannot be less than rhs
- return true;
-}
+struct LibGreaterThan
+{
+ typedef bool result_type;
+ result_type operator()(const QString &lhs, const QString &rhs) const
+ {
+ const QVector<QStringRef> lhsparts = lhs.splitRef(QLatin1Char('.'));
+ const QVector<QStringRef> rhsparts = rhs.splitRef(QLatin1Char('.'));
+ Q_ASSERT(lhsparts.count() > 1 && rhsparts.count() > 1);
+
+ // note: checking rhs < lhs, the same as lhs > rhs
+ return std::lexicographical_compare(rhsparts.begin() + 1, rhsparts.end(),
+ lhsparts.begin() + 1, lhsparts.end(),
+ NumericallyLess());
+ }
+};
#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
static int dlIterateCallback(struct dl_phdr_info *info, size_t size, void *data)
@@ -539,7 +541,7 @@ static QStringList findAllLibSsl()
QDir dir(path);
QStringList entryList = dir.entryList(QStringList() << QLatin1String("libssl.*"), QDir::Files);
- std::sort(entryList.begin(), entryList.end(), libGreaterThan);
+ std::sort(entryList.begin(), entryList.end(), LibGreaterThan());
foreach (const QString &entry, entryList)
foundSsls << path + QLatin1Char('/') + entry;
}
@@ -556,7 +558,7 @@ static QStringList findAllLibCrypto()
QDir dir(path);
QStringList entryList = dir.entryList(QStringList() << QLatin1String("libcrypto.*"), QDir::Files);
- std::sort(entryList.begin(), entryList.end(), libGreaterThan);
+ std::sort(entryList.begin(), entryList.end(), LibGreaterThan());
foreach (const QString &entry, entryList)
foundCryptos << path + QLatin1Char('/') + entry;
}