Merge pull request #5965 from Icinga/feature/json-casts

Avoid unnecessary casts in the JSON encoder
This commit is contained in:
Michael Friedrich 2018-01-11 09:37:19 +01:00 committed by GitHub
commit c2fedb3076
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 6 deletions

View File

@ -81,12 +81,24 @@ static void Encode(yajl_gen handle, const Value& value)
break;
case ValueObject:
if (value.IsObjectType<Dictionary>())
EncodeDictionary(handle, value);
else if (value.IsObjectType<Array>())
EncodeArray(handle, value);
else
yajl_gen_null(handle);
{
const Object::Ptr& obj = value.Get<Object::Ptr>();
Dictionary::Ptr dict = dynamic_pointer_cast<Dictionary>(obj);
if (dict) {
EncodeDictionary(handle, dict);
break;
}
Array::Ptr arr = dynamic_pointer_cast<Array>(obj);
if (arr) {
EncodeArray(handle, arr);
break;
}
}
yajl_gen_null(handle);
break;
case ValueEmpty: