QJsonDocument: don't re-call QVariant::type() in if-else chain

Replace if-else chain with switch statement.

Change-Id: Idd2d0198178685bdaf8f77fa6cae5025ea9de561
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Anton Kudryavtsev 2016-10-18 14:55:38 +03:00
parent e80faf3db6
commit 3d76031217

View File

@ -268,14 +268,21 @@ QJsonDocument QJsonDocument::fromBinaryData(const QByteArray &data, DataValidati
QJsonDocument QJsonDocument::fromVariant(const QVariant &variant)
{
QJsonDocument doc;
if (variant.type() == QVariant::Map) {
switch (variant.type()) {
case QVariant::Map:
doc.setObject(QJsonObject::fromVariantMap(variant.toMap()));
} else if (variant.type() == QVariant::Hash) {
break;
case QVariant::Hash:
doc.setObject(QJsonObject::fromVariantHash(variant.toHash()));
} else if (variant.type() == QVariant::List) {
break;
case QVariant::List:
doc.setArray(QJsonArray::fromVariantList(variant.toList()));
} else if (variant.type() == QVariant::StringList) {
break;
case QVariant::StringList:
doc.setArray(QJsonArray::fromStringList(variant.toStringList()));
break;
default:
break;
}
return doc;
}