QVariant: optimize convert() for bool case

Do not create QByteArray from const char* to compare with other
QByteArray, because there is an overloaded operator==.
So avoid needless allocations.

Reorder condition, because isEmpty() method is cheaper than
string compare.

Change-Id: I8d2c8a0fb247528d9ce485007431167372d62bff
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Anton Kudryavtsev 2016-10-18 17:44:54 +03:00 committed by Anton Kudryavtsev
parent 65d4880877
commit fec08545ff

View File

@ -319,7 +319,7 @@ template<typename TInput, typename LiteralWrapper>
inline bool qt_convertToBool(const QVariant::Private *const d)
{
TInput str = v_cast<TInput>(d)->toLower();
return !(str == LiteralWrapper("0") || str == LiteralWrapper("false") || str.isEmpty());
return !(str.isEmpty() || str == LiteralWrapper("0") || str == LiteralWrapper("false"));
}
/*!
@ -700,7 +700,7 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
bool *b = static_cast<bool *>(result);
switch(d->type) {
case QVariant::ByteArray:
*b = qt_convertToBool<QByteArray, QByteArray>(d);
*b = qt_convertToBool<QByteArray, const char*>(d);
break;
case QVariant::String:
*b = qt_convertToBool<QString, QLatin1String>(d);