QCommandLineOption: add some Q_UNLIKELY

These are all error conditions, and should not happen in practice.

Naturally, there's no savings in executable size, because the
compiler just shuffles the layout of the branches around.

Change-Id: I52b98cc696fd808735c7d73c1f21e02478ff4f5a
Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
Marc Mutz 2015-06-27 11:13:10 +02:00
parent cde7f1b469
commit 73991bee38

View File

@ -252,15 +252,15 @@ namespace {
result_type operator()(const QString &name) const Q_DECL_NOEXCEPT
{
if (name.isEmpty())
if (Q_UNLIKELY(name.isEmpty()))
return warn("be empty");
const QChar c = name.at(0);
if (c == QLatin1Char('-'))
if (Q_UNLIKELY(c == QLatin1Char('-')))
return warn("start with a '-'");
if (c == QLatin1Char('/'))
if (Q_UNLIKELY(c == QLatin1Char('/')))
return warn("start with a '/'");
if (name.contains(QLatin1Char('=')))
if (Q_UNLIKELY(name.contains(QLatin1Char('='))))
return warn("contain a '='");
return false;
@ -276,7 +276,7 @@ namespace {
// static
QStringList QCommandLineOptionPrivate::removeInvalidNames(QStringList nameList)
{
if (nameList.isEmpty())
if (Q_UNLIKELY(nameList.isEmpty()))
qWarning("QCommandLineOption: Options must have at least one name");
else
nameList.erase(std::remove_if(nameList.begin(), nameList.end(), IsInvalidName()),